This is a discussion on create variable before redirection. within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I'm trying to set a variable before redirection. Here is the code: //header("Location: /ManageProfile.php?UserID=".$...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I'm trying to set a variable before redirection. Here is the code:
//header("Location: /ManageProfile.php?UserID=".$id); echo("<input name=\"UserID\" type=\"Hidden\" id=\"UserID\" value=\"".$id."\">"); header("Location: /ManageProfile.php"); The commented line works fine but has the UserID in the URL, and I must avoid this. Instead, the second syntax does not work. I've error Cannot modify header information - headers already sent by..... It's there any way to redirect the page other than header. (I come from ASP, and there was a response.redirect that allow this, I mean to set values in hidden variables and then redirect.) Please help.... |
|
|||
|
*** Bob Bedford wrote/escribió (Thu, 11 Dec 2003 15:29:33 +0100):
> It's there any way to redirect the page other than header. (I come from ASP, > and there was a response.redirect that allow this, I mean to set values in > hidden variables and then redirect.) This is not a PHP issue. No matter how you do it (ASP, PHP, cgi-bin...), the final result is sending an HTTP redirect header to browser. And you can't send HTTP headers once you've started sending normal output. What's the purpose of sending an HTML form just before a redirect? -- -- -- Álvaro G. Vicario - Burgos, Spain -- |
|
|||
|
"Alvaro G Vicario" <alvaro_QUITAR_REMOVE@telecomputeronline.com> wrote in
message news:ony8h32eso5n.ql1mb7gj0chl.dlg@40tude.net... > > What's the purpose of sending an HTML form just before a redirect? > > I've got a purpose for it, since I think I need the same... I want to send order info into the dB when the usr clicks a Paypal button, which redirects to their paypal account. I'm guessing the <action="doit.php"> should : doit.php <? //put the stuff from the form into the dB header(paypal.com...); and so on... ?> Am I going about this wrong? |
|
|||
|
"Bob Bedford" a écrit le 11/12/2003 :
> I'm trying to set a variable before redirection. Here is the code: > > //header("Location: /ManageProfile.php?UserID=".$id); > echo("<input name=\"UserID\" type=\"Hidden\" id=\"UserID\" > value=\"".$id."\">"); > header("Location: /ManageProfile.php"); > > The commented line works fine but has the UserID in the URL, and I must > avoid this. Instead, the second syntax does not work. I've error Cannot > modify header information - headers already sent by..... > > It's there any way to redirect the page other than header. (I come from ASP, > and there was a response.redirect that allow this, I mean to set values in > hidden variables and then redirect.) > > Please help.... You must not echo() before a Header() because doing this PHP does send the header then the content of the echo(). The way you explain it I understand you need to send a POST variable. I would consider using a HTML form auto-submitted by some JavaScript. Otherwose why don't you send GET data ? -- Avez-vous lu le manuel? http://www.php.net/manual/fr/ |
|
|||
|
As said in my message, I won't the variables to be sent in the URL.
On ASP, you can do a Response.redirect after setting some values. Here I want to set values before redirecting to an other page. It's there any similar that let me do the same as Header, but letting me to set some values first ? "Anyway, oui, j'ai lu le manuel, et j'ai rien trouvé..." "Jedi121" <jedi121news@free.fr.Removethis> a écrit dans le message de news:mesnews.5cb87d3c.5ce65d61.332.2689@free.fr.Re movethis... > "Bob Bedford" a écrit le 11/12/2003 : > > I'm trying to set a variable before redirection. Here is the code: > > > > //header("Location: /ManageProfile.php?UserID=".$id); > > echo("<input name=\"UserID\" type=\"Hidden\" id=\"UserID\" > > value=\"".$id."\">"); > > header("Location: /ManageProfile.php"); > > > > The commented line works fine but has the UserID in the URL, and I must > > avoid this. Instead, the second syntax does not work. I've error Cannot > > modify header information - headers already sent by..... > > > > It's there any way to redirect the page other than header. (I come from ASP, > > and there was a response.redirect that allow this, I mean to set values in > > hidden variables and then redirect.) > > > > Please help.... > > You must not echo() before a Header() because doing this PHP does send > the header then the content of the echo(). > The way you explain it I understand you need to send a POST variable. > I would consider using a HTML form auto-submitted by some JavaScript. > Otherwose why don't you send GET data ? > > -- > Avez-vous lu le manuel? > http://www.php.net/manual/fr/ > |
|
|||
|
Hi Alvaro, thanks for your reply,
I've my page: login.php. The form in login.php has the result in itself. So after sumbitting itself, I must check if the user exists. If yes, I must redirect to the manage.php. The manage PHP must know wich is the selected user (giving the UserID). The UserID, for now, is in the URL: header("Location: /ManageProfile.php?UserID=".$id); Is what I'm trying to avoid. I don't want the user to see wich UserID it has. That seems to be a very common problem, why the solution would be so difficult ???? BoB "Alvaro G Vicario" <alvaro_QUITAR_REMOVE@telecomputeronline.com> a écrit dans le message de news:ony8h32eso5n.ql1mb7gj0chl.dlg@40tude.net... > *** Bob Bedford wrote/escribió (Thu, 11 Dec 2003 15:29:33 +0100): > > It's there any way to redirect the page other than header. (I come from ASP, > > and there was a response.redirect that allow this, I mean to set values in > > hidden variables and then redirect.) > > This is not a PHP issue. No matter how you do it (ASP, PHP, cgi-bin...), > the final result is sending an HTTP redirect header to browser. And you > can't send HTTP headers once you've started sending normal output. > > What's the purpose of sending an HTML form just before a redirect? > > > -- > -- > -- Álvaro G. Vicario - Burgos, Spain > -- |
|
|||
|
"Bob Bedford" a écrit le 11/12/2003 :
> As said in my message, I won't the variables to be sent in the URL. > > On ASP, you can do a Response.redirect after setting some values. > Here I want to set values before redirecting to an other page. Maybe but not in PHP as far as I know. As I said the only solution I see then is an HTML form containing hidden var you auto-submit via JavaScript. > It's there any similar that let me do the same as Header, but letting me to > set some values first ? > > "Anyway, oui, j'ai lu le manuel, et j'ai rien trouvé..." I use automated signature on these newsgroup because many of the questions can be answered by a good reading of the official manual. Don't take it personnaly. |
|
|||
|
"Jedi121" <jedi121news@free.fr.Removethis> a écrit dans le message de news:mesnews.5d267d3c.ec7fc11c.339.2689@free.fr.Re movethis... > "Bob Bedford" a écrit le 11/12/2003 : > > As said in my message, I won't the variables to be sent in the URL. > > > > On ASP, you can do a Response.redirect after setting some values. > > Here I want to set values before redirecting to an other page. > > Maybe but not in PHP as far as I know. > As I said the only solution I see then is an HTML form containing > hidden var you auto-submit via JavaScript. I've tried this, but don't seems to work: <form name="voidform" method="GET"> <input name="PrevPage" type="hidden" value="ManageProfile.php"> <input name="UserID" type="hidden" value="<?PHP echo($id);?>"> </form> <table width="100%" border="0"> <tr> <td><a href="EditUser.php?UserID=<?PHP echo($id);?>">Modifier données utilisateur</a></td> .... Isn't possible to set those values without a form. I've seen $global, or it is possible to store values in the $session variable to pass them trought the pages. > > It's there any similar that let me do the same as Header, but letting me to > > set some values first ? > > > > "Anyway, oui, j'ai lu le manuel, et j'ai rien trouvé..." > > I use automated signature on these newsgroup because many of the > questions can be answered by a good reading of the official manual. > Don't take it personnaly. > Wasn't taked personally ;-) I guessed it was an automated signature. |
|
|||
|
On Thu, 11 Dec 2003 21:03:30 +0100, "Bob Bedford"
<bedford1@YouKnowWhatToDohotmail.com> wrote: >On ASP, you can do a Response.redirect after setting some values. >Here I want to set values before redirecting to an other page. That's because of buffering. You can do the same in PHP, if you really want. http://www.php.net/manual/en/ref.outcontrol.php Although it's a bit of a waste of time outputting data but then redirecting away from it before it's seen. -- Andy Hassall (andy@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk) Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space) |
|
|||
|
"Bob Bedford" a écrit le 11/12/2003 :
> I've tried this, but don't seems to work: > <form name="voidform" method="GET"> > <input name="PrevPage" type="hidden" value="ManageProfile.php"> > <input name="UserID" type="hidden" value="<?PHP echo($id);?>"> > </form> Then you need to submit this form via a JavaScript function adding this line in your HTML section : <script language="JavaScript">document.form[0].submit();</script> > <table width="100%" border="0"> > <tr> > <td><a href="EditUser.php?UserID=<?PHP echo($id);?>">Modifier > données utilisateur</a></td> > ... > > Isn't possible to set those values without a form. I've seen $global, or it > is possible to store values in the $session variable to pass them trought > the pages. $global is just valid during the execution of the current script not form one script to another. But yes you can use sessions but then you must set the correct values of PHP.ini to be sure this data won't be shown in the URL. Depending if you tolerate the use of cookies or not. -- Have you read the manual ? http://www.php.net/manual/en/ |