简体   繁体   English

带有php的URL查询字符串

[英]URL querystring with a php include

I'm trying to include a file to output in a tab on a page. 我正在尝试将一个文件包含在页面上的选项卡中输出。 The file itself will pull up just fine, but when I try to add the required querystring to it, it gives me a "failed to open stream: No such file or directory" error. 文件本身会很好,但是当我尝试向它添加所需的查询字符串时,它会给我一个“无法打开的流:没有这样的文件或目录”错误。

I've tried just a straight include and tried setting the querystring as a variable. 我尝试过直接包含并尝试将查询字符串设置为变量。 Here's where I'm at right now. 这就是我现在所处的位置。

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

Has anyone successfully done this? 有没有人成功完成这个?

You can't include a query string in an include() . 您不能在include()包含查询字符串。

Assuming this is a local script, you could use: 假设这是一个本地脚本,您可以使用:

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

if it's a remote script on a different server, don't use include. 如果它是不同服务器上的远程脚本,请不要使用include。

I created a variable on the 2nd page - and passed it a value on the first page - and it worked for me: 我在第二页上创建了一个变量 - 并在第一页上传递了一个值 - 它对我有用:

*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;
 }

I modify the accepted answer given by Frank Farmer a bit to work for different queries: 我修改了Frank Farmer给出的接受的答案,以便为不同的查询工作:

Include twice would cause problem: 包含两次会导致问题:

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

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

For those who encounter this multiple include problem, you could wrap you code inside "agentview.php" in a function: 对于那些遇到这个多重包含问题的人,可以将代码包装在函数中的“agentview.php”中:

Inside agentview.php 在agentview.php里面

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

file need to call agentview.php 文件需要调用agentview.php

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

Hope it helps someone encounter the same problem like me and thanks Frank Farmer for the great solution which saved me alot of time. 希望它可以帮助有人遇到像我这样的问题,并感谢Frank Farmer提供了很好的解决方案,这为我节省了很多时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM