Page 1 of 1
Super-Globals not available from other pages
Posted: Fri Jul 25, 2008 5:09 pm
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.
Re: Super-Globals not available from other pages
Posted: Fri Jul 25, 2008 5:27 pm
by Eran
$_POST would only be populated for a page requested with POST headers... what exactly are you hoping to find there?
Re: Super-Globals not available from other pages
Posted: Fri Jul 25, 2008 5:29 pm
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
Re: Super-Globals not available from other pages
Posted: Fri Jul 25, 2008 5:47 pm
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.
Re: Super-Globals not available from other pages
Posted: Fri Jul 25, 2008 6:37 pm
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.
Re: Super-Globals not available from other pages
Posted: Fri Jul 25, 2008 7:04 pm
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.