带有php的URL查询字符串

时间:2011-05-13 23:20:43

标签: php

我正在尝试在页面的标签页中包含要输出的文件。文件本身会很好,但是当我尝试向它添加所需的查询字符串时,它会给我一个“无法打开的流:没有这样的文件或目录”错误。

我尝试过直接包含并尝试将查询字符串设置为变量。这就是我现在所处的位置。

$listingVars = '?mls=' . $_REQUEST['mlid'] . '&lid=0&v=agent';include("agentview.php$listingVars");

有没有人成功完成过这项工作?

3 个答案:

答案 0 :(得分:12)

您不能在include()中包含查询字符串。

假设这是一个本地脚本,您可以使用:

$_REQUEST['mls'] = $_REQUEST['mlid'];
$_REQUEST['lid'] = 0;
$_REQUEST['v'] = 'agent';
include("agentview.php");

如果它是不同服务器上的远程脚本,请不要使用include。

答案 1 :(得分:3)

我在第二页上创建了一个变量 - 并在第一页上传递了一个值 - 它对我有用:

*Page with include: 'index.php'
 <?php $type= 'simple'; include('includes/contactform.php'); ?>


*Page included: 'includes/contactform.php'

 switch($type){
  case 'simple':
   //Do something simple
  break;

  default:
   //Do something else
  break;
 }

答案 2 :(得分:1)

我修改了Frank Farmer给出的接受的答案,以便为不同的查询工作:

包含两次会导致问题:

$_REQUEST['mls'] = $_REQUEST['mlid'];
$_REQUEST['lid'] = 0;
$_REQUEST['v'] = 'agent';
include("agentview.php");

//changing the v to another
$_REQUEST['v'] = 'agent2';
include("agentview.php");

对于那些遇到这个多重包含问题的人,可以将代码包装在&#34; agentview.php&#34;在一个函数中:

在agentview.php内部

function abc($mls,$lid,$v){
   ...your original codes here...
}

文件需要调用agentview.php

include_once("agentview.php");
abc($_REQUEST['mlid'], 0, 'agent');
abc($_REQUEST['mlid'], 0, 'agent2');

希望有人能像我一样遇到同样的问题,并感谢Frank Farmer提供了很好的解决方案,为我节省了很多时间。