Home > Backend Development > PHP Tutorial > Example of include() passing with reference in php_PHP tutorial

Example of include() passing with reference in php_PHP tutorial

WBOY
Release: 2016-07-13 10:56:38
Original
841 people have browsed it

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; ?>
With a slight change, define the $_GET variable before include, and it will run normally: index.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

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...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template