包含PHP脚本时传递参数 [英] Passing parameter while including PHP script

查看:104
本文介绍了包含PHP脚本时传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这样做,但它给出了错误:(为了更好地理解我的问题,我给出了一个例子:

I want to do this, but it gives error :( for better understanding my problem I'm giving an example:

<?php
include 'script.php?text=hiii';
?>

script.php的内容

content of the script.php

<?php
echo $_GET['text'];
?>

那么,我怎样才能在包含脚本页?

So, how can i pass an argument while including the script page?

推荐答案

你可以设置 $ _ GET ['text'] 在包含文件之前:

You could set $_GET['text'] before including the file:

$_GET['text'] = 'hiii';
include 'script.php';

但这显然不会影响其他变量,例如 $ _ SERVER ['REQUEST_URI'] $ _ SERVER ['QUERY_STRING'] 等。

But this obviously won’t affect other variables like $_SERVER['REQUEST_URI'], $_SERVER['QUERY_STRING'] etc.

这篇关于包含PHP脚本时传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆