[nycphp-talk] Passing some form values through to a redirected page...

Webapprentice webapprentice at
Sat Feb 1 19:38:44 EST 2003

>	Sure; all global variables are still available to include()'d 
>and/or require()'d scripts.  $HTTP_XXX_VARS, however, does require the
>"global" declaration if you use it inside the scope of a function.
>In more recent versions, the $_POST, $_GET, etc. arrays are "superglobals"
>which means you don't have to use the "global" declaration with them;
>they're available everywhere.  Plus, $_POST is much easier to type.
If I had a function doThis(), do you mean...

function doThis() {
    global $HTTP_POST_VARS;

The server I'm on does not support $_POST, etc.  The version of PHP is 

>> >       Also, I don't know how much data is getting POSTed, but if
>> >it's more than a few hundred characters (or has the potential to be),
>> >you might have problems doing Location: redirects with all that data.
>> >I could explain this further if it doesn't make sense.
>> >  
>> >
>	This is actually the difference between the GET and POST method
>for HTTP.  You know how your HTML form can have an METHOD of either "GET"
>or "POST".  If it's GET, your browser simply (?) throws all the fields
>together and puts them on the end of your ACTION URL.  Example:
>Name: <INPUT NAME="myname" SIZE=20> <BR>
>Question: <TEXTAREA NAME="myquestion" COLS=30 ROWS=8></TEXTAREA> <BR>
><INPUT TYPE=SUBMIT VALUE="Submit Question">
In the past, I typically used POST to avoid long URLs and revealing data 
in the URL.  So, I'm ok there.

>	Another issue with redirects from a form-submit (GET or POST) is that
>the posted data is not actually available to the redirected script.  So if you
>post to /scriptA.php which does nothing except redirect to /scriptB.php, 
>scriptB.php will not actually see the submitted data, unless scriptA.php sticks
>it on the end of the redirected URL, like the browsers do.  Either way, the
>redirected script will have to use the GET method, even if the browser request
>was a POST method.
This is good to know.  So redirection would only allow a GET method if I 
tell scriptA.php to add information to the URL  of the redirection.

Like this?
header("Location: scriptB.php?myname=George");

Is this what you mean?

>	Hope that's not too verbose; I just had a Code Red.
Good explanations are perfectly fine by me.  The more I know, the safer 
the coding world will be. *grins*


More information about the talk mailing list