Php 通过包含中的url发送变量

Php 通过包含中的url发送变量,php,Php,我试图通过url向搜索页面发送一个变量“q”。但我得到的错误是 致命错误:require():无法打开require 'theme/_modules/contact/search.php?q={echo$q;}' (include_path='。:/usr/lib/php:/usr/local/lib/php') 这是我的密码 if(isset($_POST['q'])){ $q= $_POST['q']; } require 'theme/header.php

我试图通过url向搜索页面发送一个变量“q”。但我得到的错误是

致命错误:require():无法打开require 'theme/_modules/contact/search.php?q={echo$q;}' (include_path='。:/usr/lib/php:/usr/local/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.您必须允许:.2.您的链接应类似于url)

现在您正试图要求
theme/\u modules/contact/search.php?q=saman
这意味着您的脚本将查找名为
search.php?q=saman
的文件。你有那个档案吗?不,只有search.php

但是,我认为,您正在尝试将变量传递给文件。有更好的办法。只需要它,不需要额外的参数


另外,如果search.php从GET接收到值,并且您需要该结果,您可以使用该结果,因为远程包含是危险的。

谢谢。但是我得到了错误<代码>警告:require(theme/_modules/contact/search.php?q=saman):无法打开流:第17行的/home/dr7bf45v/public_html/search.php中没有这样的文件或目录但是我确信我在theme/_modules/contact/更新你的帖子中有search.php文件来保存当前代码。你确定该文件存在吗?