Bluehost.com Web Hosting $6.95

create variable before redirection.

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=".$...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-11-2003
Bob Bedford
 
Posts: n/a
Default create variable before redirection.

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....


Reply With Quote
  #2 (permalink)  
Old 12-11-2003
Alvaro G Vicario
 
Posts: n/a
Default Re: create variable before redirection.

*** 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
--
Reply With Quote
  #3 (permalink)  
Old 12-11-2003
Matthew Crouch
 
Posts: n/a
Default Re: create variable before redirection.

"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?


Reply With Quote
  #4 (permalink)  
Old 12-11-2003
Jedi121
 
Posts: n/a
Default Re: create variable before redirection.

"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/

Reply With Quote
  #5 (permalink)  
Old 12-11-2003
Bob Bedford
 
Posts: n/a
Default Re: create variable before redirection.

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/
>



Reply With Quote
  #6 (permalink)  
Old 12-11-2003
Bob Bedford
 
Posts: n/a
Default Re: create variable before redirection.

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
> --



Reply With Quote
  #7 (permalink)  
Old 12-11-2003
Jedi121
 
Posts: n/a
Default Re: create variable before redirection.

"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.


Reply With Quote
  #8 (permalink)  
Old 12-11-2003
Bob Bedford
 
Posts: n/a
Default Re: create variable before redirection.


"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&eacute;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.


Reply With Quote
  #9 (permalink)  
Old 12-11-2003
Andy Hassall
 
Posts: n/a
Default Re: create variable before redirection.

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)
Reply With Quote
  #10 (permalink)  
Old 12-11-2003
Jedi121
 
Posts: n/a
Default Re: create variable before redirection.

"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&eacute;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/

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 12:17 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0