Super-Globals not available from other pages

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rhecker
Forum Contributor
Posts: 178
Joined: Fri Jul 11, 2008 5:49 pm

Super-Globals not available from other pages

Post by rhecker »

I created a form with the post method. I can call $_POST from the page with the form itself, but not from a different page on the same site. What might I be doing wrong?

For instance, the following code returns values on the form page, but not the other page.

<?php
echo '<pre>';
print_r($_POST);
echo '</pre>';

?>

Thanks for any thoughts.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Super-Globals not available from other pages

Post by Eran »

$_POST would only be populated for a page requested with POST headers... what exactly are you hoping to find there?
User avatar
deejay
Forum Contributor
Posts: 201
Joined: Wed Jan 22, 2003 3:33 am
Location: Cornwall

Re: Super-Globals not available from other pages

Post by deejay »

you'll only be able to retrieve what's in $_POST in the page that you've sent it through in the <FORM> tag. So if its sent to PHP_SELF it'll be the same page or if you want to retrieve in another page you'll have to send it there.

hope this helps
rhecker
Forum Contributor
Posts: 178
Joined: Fri Jul 11, 2008 5:49 pm

Re: Super-Globals not available from other pages

Post by rhecker »

Thanks pytrin and deejay for your responses.

The book "Codin' for the Web" says "super-global arrays are so called because the data they contain is available at any time from any page."

Both of your resposes suggest that this isn't exactly so. How then do I send these variables to a different page?

Thanks for your help with this.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Super-Globals not available from other pages

Post by Christopher »

rhecker wrote:The book "Codin' for the Web" says "super-global arrays are so called because the data they contain is available at any time from any page."
Not a very well written sentence, but technically true. (note to self: don't by books named Codin' ;)) All superglobal variables are available everywhere. But whether they contain data and what data they contain is a different matter than their scope. Some like $_SERVER['SERVER_NAME'] always contain the same value. $_POST contains whatever HTTP POST data was submitted to the current page.
rhecker wrote:Both of your resposes suggest that this isn't exactly so. How then do I send these variables to a different page?
You can get the values from the $_POST array and add them to the appropriate link URLs on the page so the values are passed forward. Or you can save them in a cookie, the session, a file, a database, etc.
(#10850)
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Super-Globals not available from other pages

Post by Eran »

The book "Codin' for the Web" says "super-global arrays are so called because the data they contain is available at any time from any page."
Actually this is incorrect. Super global arrays are available everywhere, but the data they contain is different depending on the environment.
Post Reply