create variable before redirection.

Ask a Question related to PHP Development, Design and Development.

  1. #1

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


    Bob Bedford Guest

  2. Similar Questions and Discussions

    1. Using a Variable to create the SQL Query
      I need to create a "dynamic" Update query. I want to store the meet of the command in a variable and then reference the variable in in query. ...
    2. Create Variable
      Hi, I wanted to ask, how can I for Simple Connection component, username text field, set a variable? Thanks Lanex:beer;
    3. Create custom CGI. variable
      Does anyone know how I could create a variable that would appear in the #cgi# scope ? I have x number of coldfusion servers and on each one of...
    4. create a dynamic variable
      Hi ! i would like to know how to create a dynamic variable with flash. I'm getting 2 strings from XML and would like to create a variable named...
    5. header() redirection/session variable problem
      Hello, I'm having an odd problem with combining an authentication session variable with header() redirection. Basically I have an authentication...
  3. #2

    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
    --
    Alvaro G Vicario Guest

  4. #3

    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?


    Matthew Crouch Guest

  5. #4

    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?
    [url]http://www.php.net/manual/fr/[/url]

    Jedi121 Guest

  6. #5

    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?
    > [url]http://www.php.net/manual/fr/[/url]
    >

    Bob Bedford Guest

  7. #6

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

    Bob Bedford Guest

  8. #7

    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.


    Jedi121 Guest

  9. #8

    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.


    Bob Bedford Guest

  10. #9

    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.

    [url]http://www.php.net/manual/en/ref.outcontrol.php[/url]

    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) ([url]http://www.andyh.co.uk[/url])
    Space: disk usage analysis tool ([url]http://www.andyhsoftware.co.uk/space[/url])
    Andy Hassall Guest

  11. #10

    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 ?
    [url]http://www.php.net/manual/en/[/url]

    Jedi121 Guest

  12. #11

    Default Re: create variable before redirection.

    *** Bob Bedford wrote/escribió (Thu, 11 Dec 2003 21:09:01 +0100):
    > 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's a typical usage for sessions. You set a session variable and
    redirect afterwards:

    $_SESSION['id']=$id;
    header("Location: [url]http://www.site.com/ManageProfile.php);[/url]
    exit;

    Then you have that variable available everywhere:

    echo $_SESSION['id'];

    BTW, this code is untested, check sessions manual chapter.

    --
    --
    -- Álvaro G. Vicario - Burgos, Spain
    --
    Alvaro G Vicario Guest

  13. #12

    Default Re: create variable before redirection.

    *** Bob Bedford wrote/escribió (Thu, 11 Dec 2003 21:03:30 +0100):
    > On ASP, you can do a Response.redirect after setting some values.
    > Here I want to set values before redirecting to an other page.
    Do you mean ASP.NET? In old-fashioned ASP I can't remember you could do
    such a thing. Well, you could set any value you want (just like in PHP) but
    you can't send it to the redirected page unless you use URL, cookies or
    sessions.


    --
    --
    -- Álvaro G. Vicario - Burgos, Spain
    --
    Alvaro G Vicario Guest

  14. #13

    Default Re: create variable before redirection.

    "Alvaro G Vicario" <alvaro_QUITAR_REMOVE@telecomputeronline.com> a écrit
    dans le message de news:19gusk0oqerab.10n1bdt76wjds.dlg@40tude.net...
    > *** Bob Bedford wrote/escribió (Thu, 11 Dec 2003 21:03:30 +0100):
    > > On ASP, you can do a Response.redirect after setting some values.
    > > Here I want to set values before redirecting to an other page.
    >
    > Do you mean ASP.NET? In old-fashioned ASP I can't remember you could do
    > such a thing. Well, you could set any value you want (just like in PHP)
    but
    > you can't send it to the redirected page unless you use URL, cookies or
    > sessions.
    sessions also create cookies, and this is a problem, since if the user
    disable cookies, I get stuck and can't manage the session correctly.

    I'm looking for an other way to do so. I've been told to use a javascript
    that submit the form automatically, maybe I'll try this.

    Thanks for help.


    Bob Bedford Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139