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?

Link to comment
Share on other sites

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.

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.