PHP包含HTTP get参数
如何使用包含路径末尾带有GET参数的php include() 即:PHP包含HTTP get参数,php,Php,如何使用包含路径末尾带有GET参数的php include() 即: 您不需要,include通过本地文件系统加载文件 如何使用包含路径末尾带有GET参数的php include() 您可以将以下内容写入$\u GET: $_GET["id"] = 5; // Don't do this at home! include("....."); 但这让人觉得笨拙和错误。如果可能,使包含的文件接受正常变量: $id = 5; include("....."); // included file
您不需要,
include
通过本地文件系统加载文件
如何使用包含路径末尾带有GET参数的php include()
您可以将以下内容写入$\u GET
:
$_GET["id"] = 5; // Don't do this at home!
include(".....");
但这让人觉得笨拙和错误。如果可能,使包含的文件接受正常变量:
$id = 5;
include("....."); // included file handles `$id`
如果你真的想,你可以这样做,结果也是一样的
<?php
$_GET['id'] = 5;
include "/home/site/public_html/script.php";
?>
但是,您也可以定义变量并包含它
<?php
$id = 5;
include "/home/site/public_html/script.php";
?>
并在script.php中引用变量$id
。您可以使用:
include("http://localhost/include/that/thing.php?id=554&y=16");
但这是非常有用的
可能会为此编写一个脚本,因此本地脚本也有可能
include("withvars:./include/that/thing.php?id=554");
我不知道这样的解决方案是否存在。这是不可能的
include
从文件系统读取文件,不启动HTTP请求。好的,您到底想做什么?如果需要将值传递给script.php
,它将能够读取调用脚本中现有的$\u GET
。在包含的文件中包含函数或类,并将所需的变量作为参数传递给函数/构造函数可能会更整洁。除非指定的路径是url,在这种情况下,将通过http请求一个“http://”类型的路径,但这非常难看,而且非常不安全。(如果在PHP中启用了“URL fopen包装器”,您可以这样做,也可以让我这样呕吐。)
include("withvars:./include/that/thing.php?id=554");