Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL querystring with a php include

Tags:

php

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?

like image 763
SickHippie Avatar asked May 13 '11 23:05

SickHippie


People also ask

What is QueryString PHP?

A query string is a part of a uniform resource locator (URL) that assigns values to specified parameters.

Which HTTP method can append query string to URL?

The append() method of the URLSearchParams interface appends a specified key/value pair as a new search parameter. As shown in the example below, if the same key is appended multiple times it will appear in the parameter string multiple times for each value.


2 Answers

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.

like image 100
Frank Farmer Avatar answered Sep 18 '22 11:09

Frank Farmer


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;
 }
like image 37
adswebwork Avatar answered Sep 19 '22 11:09

adswebwork