Jump to content

$_GET variables not working in an included PHP file


sean14592

Recommended Posts

Ok, well my problem is that I have a link which goes to for example http://mysite.com/index.php?page=listing&id=1

 

Now, The PAGE variable sets what the page is, simple.

 

Then the ID variable tells the included PAGE what content to include corrisponding to the ID.

 

I have a problem with the second part, the PAGE is included, but then the included page does not see the ID variable.

 

Heres some of my code:

Bit that includes the page

<?php


//display main content
$pagesavail = array ('home','moto','freetemp','freetempshow');

		$var1 = sanitize($_GET['oc']);


		if (in_array($var1, $pagesavail)) {

			include("http://mysite.com/include/".$var1.".php"); 
		} else {
			include("http://mysite.com/include/home.php"); 
		}


?>

Bit that includes the content based on ID

<?php
echo ("-".$_GET['id']."-<br>");  //Just to test
?>

 

As you can see from the code above the included page should display -1- (if the ID variable was set to 1), Though im seeing --

 

 

Cheers

Sean

Link to comment
Share on other sites

by including the files with the FULL url, you are including the 'generated' version of the page. So it's just as if you put

http://mysite.com/include/listing.php

into your browser, did a view source, and included that.

 

what you want, is to include the PHP source. to do this, provide the FILESYSTEM path to the file. something like:

include("include/".$var1.".php");

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.