Home > php教程 > php手册 > body text

php include()带参数实现方法

WBOY
Release: 2016-05-25 16:48:16
Original
1806 people have browsed it

inlcude带参数这个问题以前我没成功,今天看到一文章果断搞了了,如我可以这样include('a.php?site=www.phprm.com')然后在调用a.php页面可直接$_GET['a'];获取了.

具体方法详解

举例:假设在 index.php 中需要调用 inc.php?para=3 ,inc.php

实例代码如下:

echo $_GET['para']; ?>
Copy after login

下面的写法是无法得到正确结果的:

index.php

实例代码如下:

include dirname(__FILE__).'/inc.php?para=3';
Copy after login
Copy after login

稍微变通一下,把$_GET变量在include之前定义,则可以正常运行:

index.php

实例代码如下:

include dirname(__FILE__).'/inc.php?para=3';
Copy after login
Copy after login

如果php.ini中开启了allow_url_include功能,则可以使用include url的方式:

index.php

实例代码如下:

include 'http://www.phprm.com/ inc.php?para=3';
Copy after login

设置方法:php.ini中,找到如下行,改为On:

; Whether to allow include/require to open URLs (like http:// or ftp://) as files.

allow_url_include = On

不过为了保证安全性,大部分的服务器都将allow_url_include 功能关闭,那样就只能视情况而定了.

永久地址:

转载随意~请带上教程地址吧^^

Related labels:
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!