Forum Moderators: coopster

Message Too Old, No Replies

$_Post variables destroyed on redirect?

         

neophyte

11:13 am on May 29, 2005 (gmt 0)

10+ Year Member



I just want to confirm what I'm finding:

When I use a form with a "post" action, then do some error checking on the result, then redirect to a different page using header('Location: somewhere.php') I cannot access the $_POST variables anymore from the previous page.

Are they wiped out when you redirect to another page?

When I include the "somewhere.php" file within the form file, I can still get to them.

I've always wondered about this: if you create a bunch of variables on one page, then go to another page, are the variables from the previous page distroyed? Are these variables (like $somevariable) "page-specific" in scope?

I was never sure, but I had though that $_POST variables were "global" because they were "superglobal" variables, but, from the results I'm getting, they don't appear to be truly "global".

Can someone help clear my head about this?

killroy

11:36 am on May 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Globality refers to an instance of a script execution. They cennot be global across multiple scripts or wou would be stuck with the same POST variables for ever and ever thereafter!

What you want is to include the POST data in the url of the redirect, or as a session on the server.

SN

coopster

2:31 pm on May 30, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Another option is to create your own POST headers and use them in your redirect. There is an old example at Zend [zend.com...] (There is also an example [webmasterworld.com] in our PHP Forum Library).