Jump to content

Problem with $_GET vars when including a file across subdomains.


JJBlaha

Recommended Posts

This is my issue, simplified down.

 

http://sub.domain.com/page1.php

<?php

include('http://www.domain.com/main/page2.php');

?>

 

http://www.domain.com/main/page2.php

<?php

echo "Test is ";

echo $_GET['test'];

?>

 

http://sub.domain.com/page1.php?test=test returns

Test is

 

And if i change page1.php to

 

http://sub.domain.com/page1.php

<?php

echo "Test is ";

echo $_GET['test'];

?>

 

http://sub.domain.com/page1.php?test=test returns

Test is test

 

What is going on?

You can't use include() for that.  You should use readfile() instead.

 

To preserve the $_GET variables, you will need to explicitly add them to the readfile() call, like this:

 

readfile('http://www.domain.com/main/page2.php?test=test');

 

As for doing that in practice, you can hardcode it if you only expect a fixed set of $_GET variables.  Otherwise you can use a foreach loop to add each $_GET variable.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.