我试图通过url发送一个变量"q"到搜索页面。但是我得到的错误提示是
致命错误:require(): Failed open required"主题/_modules/联系/search.php吗?q ={回声问美元;}'(include_path = ':/usr/lib/php:/usr/地方/lib/php)
这是我的代码
if(isset($_POST['q'])){
$q= $_POST['q'];
}
require 'theme/header.php';
require 'theme/_modules/contact/search.php?q={echo $q;}';
require 'theme/footer.php';
谁能告诉我解决这个问题的原因和方法?谢谢你. . 做了这个之后…
require 'theme/header.php';
//require 'theme/_modules/contact/search.php?q={echo $q;}';
require "theme/_modules/contact/search.php?q=$q";
require 'theme/footer.php';
我得到错误
Warning: require(theme/_modules/contact/search.php?q=saman): failed to open stream: No such file or directory in /home/dr7bf45v/public_html/search.php on line 17
使用
require 'theme/_modules/contact/search.php?q='.$q;
当你使用这个…
require 'theme/_modules/contact/search.php?q={echo $q;}';
PHP按照字面意思解释{echo $q;}
,因为它被括在单引号中。通常PHP会将{echo $q;}
解释为您想要的双引号,但为了安全起见,使用.
来附加到字符串的末尾。如果您想将$q
用双引号括起来,而不必使用.
,请这样做…
require "theme/_modules/contact/search.php?q=$q";
我认为你是想走一条错误的路。
您正在尝试完成远程包含。(1. 必须允许在PHP中包含远程文件。2. 你的链接应该看起来像url).
现在你试图要求theme/_modules/contact/search.php?q=saman
,这意味着你的脚本寻找文件与名称search.php?q=saman
。你有那份文件吗?不。只有search.php。
但是,我认为,你试图传递变量到文件作用域。有更好的办法。只需要它而不需要额外的参数。
注:但如果search。php从GET接收值,而你需要结果,你可以使用curl,因为远程包含是危险的。