8

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?

3 Answers 3

12

You can't include a query string in an 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.

Sign up to request clarification or add additional context in comments.

2 Comments

This worked beautifully - now I have to figure out why it's breaking my JS! I'll accept this answer when I'm able to.
Is there any particular reason why you have to manually re-request the query variables this way … or, why at all?
2

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

Comments

1

I modify the accepted answer given by Frank Farmer a bit to work for different queries:

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:

Inside agentview.php

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

file need to call 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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.