我想include()
一个位于服务器上的php文件,并带有其他GET属性。
但这是行不通的:
include('search.php?q=1');
它给出的错误:
PHP Warning: include(): Failed opening './search.php?q=1' for inclusion
似乎它试图打开一个字面名为'search.php?q = 1'的文件,而不是打开'search.php'文件并发送GET属性。
*请注意,如果我不放置任何GET属性,它将起作用:
include('search.php');
最佳答案
您不需要这样做:您必须执行http请求才能传递GET参数。您以这种方式调用的PHP脚本将在单独的PHP进程中运行。
最佳方法是在本地包含文件:
include('search.php');
并手动将任何参数传递给它,例如
$q = "1";
include('search.php'); // expects `$q` parameter
或者更干净地说,将
search.php
中的所有内容放入可以使用参数调用的函数或类中:include('search.php'); // defines function my_search($q)
my_search(1);
关于php - 带有GET属性的PHP include()(include file.php?q = 1),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5675550/