Php url include

I am trying to include a file for output in a tab on a page. The file itself pulls up just fine, but when I try to add the required button to it, it gives me the error message "Could not open stream: There is no such file or directory."

I tried just turning on include and trying to set querystring as a variable. Here where I am now.

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

Has anyone successfully done this?

+7
source share
3 answers

You cannot include a query string in include() .

Assuming this is a local script, you can use:

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

if it is a remote script on another server, do not use include.

+12
source

I created a variable on page 2 - and passed the value to it 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; } 
+3
source

I am modifying the accepted answer by Frank Farrer to work for different requests:

Turning it on twice will cause a 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 are facing this issue with multiple inclusions, you can wrap the code inside "agentview.php" in a function:

Inside agentview.php

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

file must be called agentview.php

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

Hope this helps someone run into the same problem as me, and thanks to Frank Farmer for the great solution that saved me a lot of time.

+1
source

All Articles