php中include()带参考传递实例
include是php中的一个调用文件的函数,默认状态下是不可以直接像include(a.php?id=1)这样操作,下面我来介绍解决include不能带参数调用解决办法。
有时基于某些特殊需求,需要在PHP中使用include()方法调用项目中某个独立提供服务的文件,如果被调用文件使用GET方式传入数据,则需要用到一些小技巧。
举例:假设在 index.php 中需要调用 inc.php?para=3 ,
inc.php
代码如下 | 复制代码 |
下面的写法是无法得到正确结果的:
index.php
代码如下 | 复制代码 |
|
稍微变通一下,把$_GET变量在include之前定义,则可以正常运行:
index.php
代码如下 | 复制代码 |
$_GET['para'] = 3; include dirname(__FILE__).'/inc.php; ?> |
如果php.ini中开启了allow_url_include功能,则可以使用include url的方式:
index.php
代码如下 | 复制代码 |
|
设置方法:php.ini中,找到如下行,改为On:
代码如下 | 复制代码 |
; Whether to allow include/require to open URLs (like http:// or ftp://) as files. |
不过为了保证安全性,大部分的服务器都将allow_url_include 功能关闭,那样就只能视情况而定了。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 English version
Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.