具体方法详解
举例:假设在 index.php 中需要调用 inc.php?para=3 ,
inc.php
代码如下 | 复制代码 |
<?php echo $_GET['para']; ?> |
下面的写法是无法得到正确结果的:
index.php
代码如下 | 复制代码 |
<?php include dirname(__FILE__).'/inc.php?para=3'; ?> |
稍微变通一下,把$_GET变量在include之前定义,则可以正常运行:
index.php
代码如下 | 复制代码 |
<?php $_GET['para'] = 3 include dirname(__FILE__).'/inc.php; ?> |
如果php.ini中开启了allow_url_include功能,则可以使用include url的方式:
index.php
代码如下 | 复制代码 |
<?php include 'http://www.yoururl.com/inc.php?para=3'; ?> |
设置方法:php.ini中,找到如下行,改为On:
; Whether to allow include/require to open URLs (like http:// or ftp://) as files.
allow_url_include = On
不过为了保证安全性,大部分的服务器都将allow_url_include 功能关闭,那样就只能视情况而定了。
时间: 2024-09-20 21:46:12