Include is a function in PHP that calls files. By default, it cannot be operated directly like include(a.php?id=1). Let me introduce the solution to the problem that include cannot be called with parameters.
Sometimes based on some special needs, you need to use the include() method in PHP to call a file that provides independent services in the project. If the called file uses the GET method to pass in data, you need to use some tricks.
Example: Suppose you need to call inc.php?para=3 in index.php,
inc.php
The code is as follows
|
Copy code
|
The following writing method cannot get the correct result:
index.php
代码如下 |
复制代码 |
$_GET['para'] = 3;
include dirname(__FILE__).'/inc.php; ?> |
The code is as follows
|
Copy code
|
代码如下 |
复制代码 |
; Whether to allow include/require to open URLs (like http:// or ftp://) as files.
allow_url_include = On
|
| With a slight change, define the $_GET variable before include, and it will run normally:
index.php
The code is as follows
Copy code
|
$_GET['para'] = 3;
include dirname(__FILE__).'/inc.php; ?>
If the allow_url_include function is enabled in php.ini, you can use the include url method:
index.php
The code is as follows
|
Copy code
|
Setting method: In php.ini, find the following line and change it to On:
The code is as follows
|
Copy code
|
; Whether to allow include/require to open URLs (like http:// or ftp://) as files.
allow_url_include = On
However, in order to ensure security, most servers turn off the allow_url_include function, so it depends on the situation.
http://www.bkjia.com/PHPjc/632155.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632155.htmlTechArticleinclude is a function in php that calls files. By default, it cannot be used directly like include(a.php ?id=1) In this way, let me introduce the solution to the problem that include cannot be called with parameters...
|
|
|
|
|