Passing HTTP POST information to another script - How?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dave Smithz

    Passing HTTP POST information to another script - How?

    Hi there,

    I have a situation where I want to have multiple submit buttons on the same
    form and therefore want to use a redirection php script that checks the
    value associated with the submit form variable to calculate which submit was
    pressed and then redirects the user to another php page accordingly.

    I used:
    headers ("location:myph pscript.php")

    to do this.

    However automatically this does not pass on the information sent in the form
    POST. I did start looking into reencoding the $_REQUEST into a GET string to
    append to the URL, but this is a bit crude because the original form submit
    uses a post and had a lot of information (some of which is also held in
    $_FILES).

    So is there a better way to go about this? How can I simulate a POST?

    My second related question on this subject (I was going to post this
    separately but it's probably better here) is whether there is a limit to the
    amount of information that can be passed via an HTTP GET.
    I once remember reading there is a 255 character limit to a URL address and
    if this also includes the variable information after the ? this is quite
    restrictive.

    Kind regards

    Dave


  • Erwin Moller

    #2
    Re: Passing HTTP POST information to another script - How?

    "Dave Smithz" <SPAM FREE WORLD> wrote:
    [color=blue]
    > Hi there,
    >
    > I have a situation where I want to have multiple submit buttons on the
    > same form and therefore want to use a redirection php script that checks
    > the value associated with the submit form variable to calculate which
    > submit was pressed and then redirects the user to another php page
    > accordingly.
    >
    > I used:
    > headers ("location:myph pscript.php")
    >
    > to do this.
    >
    > However automatically this does not pass on the information sent in the
    > form POST. I did start looking into reencoding the $_REQUEST into a GET
    > string to append to the URL, but this is a bit crude because the original
    > form submit uses a post and had a lot of information (some of which is
    > also held in $_FILES).
    >
    > So is there a better way to go about this? How can I simulate a POST?
    >
    > My second related question on this subject (I was going to post this
    > separately but it's probably better here) is whether there is a limit to
    > the
    > amount of information that can be passed via an HTTP GET.
    > I once remember reading there is a 255 character limit to a URL address
    > and if this also includes the variable information after the ? this is
    > quite restrictive.
    >
    > Kind regards
    >
    > Dave[/color]

    Hi Dave,

    When php.net fixed their bug, look here:


    curl lets you mimic postings.

    Regards,
    Erwin Moller

    Comment

    • Colin McKinnon

      #3
      Re: Passing HTTP POST information to another script - How?

      "Dave Smithz" <SPAM FREE WORLD> wrote:
      [color=blue]
      > Hi there,
      >
      > I have a situation where I want to have multiple submit buttons on the
      > same form and therefore want to use a redirection php script that checks
      > the value associated with the submit form variable to calculate which
      > submit was pressed and then redirects the user to another php page
      > accordingly.
      >
      > I used:
      > headers ("location:myph pscript.php")
      >[/color]
      <snip>
      Change the action of the form from javascript?

      ....or...

      use a mini front controller which includes the relevant script?

      Need more?

      C.

      Comment

      • Dave Smithz

        #4
        Re: Passing HTTP POST information to another script - How?


        "Colin McKinnon" <colin.deleteth is@andthis.mms3 .com> wrote in message
        news:cv5106$o7i $1> > Hi there,[color=blue][color=green]
        > >[/color]
        > <snip>
        > Change the action of the form from javascript?[/color]

        Forgot to say I can't use Javascript - cannot risk users not having it on.
        [color=blue]
        > ...or...
        >
        > use a mini front controller which includes the relevant script?[/color]

        What is this? Does it require JavaScript?

        Cheers

        Dave


        Comment

        • Philip Ronan

          #5
          Re: Passing HTTP POST information to another script - How?

          Dave Smithz wrote:
          [color=blue]
          > Hi there,
          >
          > I have a situation where I want to have multiple submit buttons on the same
          > form and therefore want to use a redirection php script that checks the
          > value associated with the submit form variable to calculate which submit was
          > pressed and then redirects the user to another php page accordingly.[/color]

          Why can't you just combine your PHP scripts (either in a single file or with
          "require" statements)?
          [color=blue]
          > I used:
          > headers ("location:myph pscript.php")
          >
          > to do this.[/color]

          By redirecting POST requests you are asking for trouble. For example, take a
          look at <http://ppewww.ph.gla.a c.uk/~flavell/www/post-redirect.html>. A
          simple header statement just won't work properly, even if you get the syntax
          right and use an absolute URI like you're supposed to.
          [color=blue]
          > However automatically this does not pass on the information sent in the form
          > POST. I did start looking into reencoding the $_REQUEST into a GET string to
          > append to the URL, but this is a bit crude because the original form submit
          > uses a post and had a lot of information (some of which is also held in
          > $_FILES).[/color]

          By redirecting a POST request you're asking the client's browser to re-issue
          the request to a different URL. That would mean sending the file twice. I
          don't think that's a good idea. :-/
          [color=blue]
          > So is there a better way to go about this? How can I simulate a POST?[/color]

          Do all your server-side processing at the URL specified by the form's action
          attribute. That's the way things are supposed to work. Or use different
          forms linked to different server-side scripts.

          Could you perhaps explain a bit more about what you're trying to do with
          this form?
          [color=blue]
          > My second related question on this subject (I was going to post this
          > separately but it's probably better here) is whether there is a limit to the
          > amount of information that can be passed via an HTTP GET.
          > I once remember reading there is a 255 character limit to a URL address and
          > if this also includes the variable information after the ? this is quite
          > restrictive.[/color]

          I think it' more like 4096 characters, but don't take my word for it. It's
          definitely a lot more than 255.

          --
          phil [dot] ronan @ virgin [dot] net



          Comment

          • John Dunlop

            #6
            Re: Passing HTTP POST information to another script - How?

            Dave Smithz wrote:
            [color=blue]
            > My second related question on this subject (I was going to post this
            > separately but it's probably better here) is whether there is a limit to the
            > amount of information that can be passed via an HTTP GET.[/color]

            Depends.

            In theory, no. The generic URI spec does not impose a limit
            on the length of URIs, and the HTTP spec does not impose a
            limit on the length of its URIs either. From sec. 3.2.1 of
            the latter:

            | The HTTP protocol does not place any /a priori/ limit on
            | the length of a URI. Servers MUST be able to handle the
            | URI of any resource they serve, and SHOULD be able to
            | handle URIs of unbounded length if they provide GET-based
            | forms that could generate such URIs. A server SHOULD
            | return 414 (Request-URI Too Long) status if a URI is
            | longer than the server can handle ...



            So an HTTP URI with a query string ten thousand characters
            long, if unwieldy, accords with the interworking
            specifications.

            In practice, however, yes. There are implementation-
            specific limits.
            [color=blue]
            > I once remember reading there is a 255 character limit to a URL address and
            > if this also includes the variable information after the ? this is quite
            > restrictive.[/color]

            RFC2616 (1999) notes that older software might not support
            URIs longer than 255 bytes. I should like to think that
            that limit is imposed only by some archaic implementations ,
            the likes of which you'd seldom encounter nowadays.

            Slainte!

            --
            Jock

            Comment

            • Dan Stumpus

              #7
              Re: Passing HTTP POST information to another script - How?


              "Dave Smithz" <SPAM FREE WORLD> wrote in message
              news:4215e9d7$1 @news1.homechoi ce.co.uk...[color=blue]
              > Hi there,
              >
              > I have a situation where I want to have multiple submit buttons on the
              > same
              > form and therefore want to use a redirection php script that checks the
              > value associated with the submit form variable to calculate which submit
              > was
              > pressed and then redirects the user to another php page accordingly.
              >
              > I used:
              > headers ("location:myph pscript.php")[/color]
              ......[color=blue]
              > So is there a better way to go about this? How can I simulate a POST?[/color]

              You can put all kinds of data "in session".

              eg,

              in the script receiving the original POST:

              session_start() ; // should appear before *any* output in the script...
              $_SESSION['posted'] = $_POST;

              The above stores the entire post array in-session.
              Now you can redirect to any page you want, or the user can click on a link
              to a script of yours, and within that destination script you do:

              session_start() ; // should appear before *any* output in the script...
              posted = $_SESSION['entryFormValue s'];

              Now the posted array is available and has the original $_POST info from the
              original script.

              (read up on sessions...extr emely useful stuff)

              -- Dan



              Comment

              • Chung Leong

                #8
                Re: Passing HTTP POST information to another script - How?

                "Dave Smithz" <SPAM FREE WORLD> wrote in message
                news:4215e9d7$1 @news1.homechoi ce.co.uk...[color=blue]
                > Hi there,
                >
                > I have a situation where I want to have multiple submit buttons on the[/color]
                same[color=blue]
                > form and therefore want to use a redirection php script that checks the
                > value associated with the submit form variable to calculate which submit[/color]
                was[color=blue]
                > pressed and then redirects the user to another php page accordingly.
                >
                > I used:
                > headers ("location:myph pscript.php")
                >
                > to do this.[/color]

                The HTTP status code 307 is used for redirecting a POST. Only works well
                with IE though.
                [color=blue]
                > However automatically this does not pass on the information sent in the[/color]
                form[color=blue]
                > POST. I did start looking into reencoding the $_REQUEST into a GET string[/color]
                to[color=blue]
                > append to the URL, but this is a bit crude because the original form[/color]
                submit[color=blue]
                > uses a post and had a lot of information (some of which is also held in
                > $_FILES).
                >
                > So is there a better way to go about this? How can I simulate a POST?[/color]

                If session is available, you can stick the $_POST array in there:

                $key = md5(serialize($ _POST));
                $_SESSION[$key] = $_POST;
                header("Locatio n: otherfile.php?k ey=$key");

                then retrieve it in the other page:
                $_POST = $_SESSION[$_GET['key']];
                [color=blue]
                > My second related question on this subject (I was going to post this
                > separately but it's probably better here) is whether there is a limit to[/color]
                the[color=blue]
                > amount of information that can be passed via an HTTP GET.
                > I once remember reading there is a 255 character limit to a URL address[/color]
                and[color=blue]
                > if this also includes the variable information after the ? this is quite
                > restrictive.[/color]

                It was a problem affecting one of the ancient browsers. Might have been IE
                2, I can't remember. The browser would die from a stack overflow error when
                the URL is longer than 255.


                Comment

                • Dan Stumpus

                  #9
                  Re: Passing HTTP POST information to another script - How?

                  Oops! Correction:
                  [color=blue]
                  > You can put all kinds of data "in session".
                  >
                  > eg,
                  >
                  > in the script receiving the original POST:
                  >
                  > session_start() ; // should appear before *any* output in the script...
                  > $_SESSION['posted'] = $_POST;
                  >
                  > The above stores the entire post array in-session.
                  > Now you can redirect to any page you want, or the user can click on a link
                  > to a script of yours, and within that destination script you do:
                  >
                  > session_start() ; // should appear before *any* output in the script...
                  > posted = $_SESSION['entryFormValue s'];[/color]

                  Above line should be: posted = $_SESSION['posted'];

                  Sorry about that...


                  Comment

                  • Philip Ronan

                    #10
                    Re: Passing HTTP POST information to another script - How?

                    Chung Leong wrote:
                    [color=blue]
                    > The HTTP status code 307 is used for redirecting a POST. Only works well
                    > with IE though.[/color]

                    Actually it doesn't work well with IE at all.
                    See <http://ppewww.ph.gla.a c.uk/~flavell/www/post-redirect.html>

                    --
                    phil [dot] ronan @ virgin [dot] net



                    Comment

                    • R. Rajesh Jeba Anbiah

                      #11
                      Re: Passing HTTP POST information to another script - How?

                      Dave Smithz wrote:[color=blue]
                      > Hi there,
                      >
                      > I have a situation where I want to have multiple submit buttons on[/color]
                      the same[color=blue]
                      > form and therefore want to use a redirection php script that checks[/color]
                      the[color=blue]
                      > value associated with the submit form variable to calculate which[/color]
                      submit was[color=blue]
                      > pressed and then redirects the user to another php page accordingly.
                      >
                      > I used:
                      > headers ("location:myph pscript.php")
                      >
                      > to do this.
                      >
                      > However automatically this does not pass on the information sent in[/color]
                      the form[color=blue]
                      > POST. I did start looking into reencoding the $_REQUEST into a GET[/color]
                      string to[color=blue]
                      > append to the URL, but this is a bit crude because the original form[/color]
                      submit[color=blue]
                      > uses a post and had a lot of information (some of which is also held[/color]
                      in[color=blue]
                      > $_FILES).
                      >
                      > So is there a better way to go about this? How can I simulate a POST?[/color]

                      I don't know, why you have to redirect to another page. If you have
                      some good Form handler mechanism, you can do like this (in the same
                      page--even witout losing the clarity/readability/etc):

                      if ( $foo->isFormSubmitte d($_POST, 'deposit') )
                      {
                      $foo->isValidDeposit Fields() and
                      $foo->addToDepositTa ble();
                      }
                      else if ( $foo->isFormSubmitte d($_POST, 'withdraw') )
                      {
                      ...
                      }

                      --
                      <?php echo 'Just another PHP saint'; ?>
                      Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

                      Comment

                      Working...