Results 1 to 5 of 5

Thread: How to redirct POST data ? [RESOLVED]

  1. #1

    Thread Starter
    Hyperactive Member AvisSoft's Avatar
    Join Date
    Sep 2002
    Location
    Chandigarh
    Posts
    459

    Resolved How to redirct POST data ? [RESOLVED]

    Hello,

    I have a form, from where the data is being posted to a php script. Now in the php script the script has to forward the data to another script with posted data. I know this can be done using header but i don't know how to keep the data posted with form in POST method.

    For example:

    The form below:

    Code:
    <form method="POST" action="1.php">
    <input type="hidden" value="abc" name="t1">
    <input type="submit">
    </form>
    Now its posting data using POST method to 1.php...and now 1.php will redirect everything to another php script with the data and it should be in POST method ...

    How can i do this ?

    Thanks.
    Tapan Bhanot,
    CEO, Avis Software.
    Website: www.avissoftware.com

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: How to redirct POST data ?

    RFC 2616 which defines HTTP 1.1 states that when a 302 response is sent (i.e: the response code sent when the header function is called with a location header) to the client, should the original HTTP request be a POST request, the client must not redirect automatically using a POST request. This is for obvious security reasons.

    As such, most, if not all web browsers redirect using the GET method if the original was a POST. However, in HTTP 1.1, the 307 response was introduced which requires the client to redirect using the same method as the original. To redirect with a 307 response you need to call the header function twice:
    PHP Code:
    header('HTTP/1.1 307 Temporary Redirect');
    header('Location: http://www.redirect.com/'); 
    However, if the client made the request using a HTTP 1.0 browser, this would not work. So you should check the HTTP version is 1.1 using the $_SERVER['SERVER_PROTOCOL'] variable before using this. Again, HTTP 1.1, requires that the client does not automatically redirect. So browsers display a warning before redirecting. You can see what kind of warning you would get by giving this script a test run:

    http://adam.codedv.com/examples/redirect_307.php

    My advice would be to temporarily store the POST data in a session and redirect using the standard method to the new script. The new script would then be able to pick up all the data from the session when the client redirects. This is the only way you can guarantee the data gets preserved through the redirect.

    Edit: Internet Explorer displays no warning, but Firefox does. Another example of non standards complience
    Last edited by visualAd; Apr 15th, 2005 at 04:49 PM.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Hyperactive Member AvisSoft's Avatar
    Join Date
    Sep 2002
    Location
    Chandigarh
    Posts
    459

    Talking Re: How to redirct POST data ?

    Hi,

    I am the only person going to use it by using IE 6. So i hope its supported. I don't want to get into session ..becuase its too complex to be used when i am going to do stuff like this.

    I just need it from 1 to another just 1 time and then it should not be there...if you can tell me some other workaround for this then it will be highly apperciaited.

    Though i guess this header 307 will work fine for me. I highly apperciate your answer. It will help me indeed.

    Thanks.
    Tapan Bhanot,
    CEO, Avis Software.
    Website: www.avissoftware.com

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: How to redirct POST data ?

    Quote Originally Posted by AvisSoft
    I just need it from 1 to another just 1 time and then it should not be there...if you can tell me some other workaround for this then it will be highly apperciaited.
    Unfortunately the use of sessions is the only proper work around and, where did you get the idea from that sessions are too complex?

    Have you tried out the link I gave in my previous post. It has a 307 redirect. In IE6 it is transparent, in Firefox you get a warning.

    This is the source for the script anyway:
    PHP Code:
    <?php
        
    if (isset($_POST['submit'])) {
            if (isset(
    $_GET['redirected'])) {
                echo(
    "Posted data:\n\n");
                
    print_r($_POST);

                exit;
            } else {
                
    header('HTTP/1.1 307 Temporary Redirect');
                
    header('Location: http://adam.codedv.com' $_SERVER['PHP_SELF'] . '?redirected=1');
            }
        }
    ?>
    <html>
        <head>
            <title>Redirect Demo</title>
        </head>
        <body>
            <form method="post" action="<?php echo($_SERVER['PHP_SELF']); ?>">
                <p>Data: <input type="text" name="data" /></p>
                <p>This form will be redirected using a 307 response. <br />
                <input type="submit" value="Submit" name="submit" /></p>
            </form>
        </body>
    </html>
    I am in the process of writing a tutorial on sessions, they really arn't that scary, I'll let you know when I'm done writing it.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5

    Thread Starter
    Hyperactive Member AvisSoft's Avatar
    Join Date
    Sep 2002
    Location
    Chandigarh
    Posts
    459

    Talking Re: How to redirct POST data ?

    Hi,

    Thanks visualAd, i tried the 307 and its working like a charm.

    Thank you.
    Tapan Bhanot,
    CEO, Avis Software.
    Website: www.avissoftware.com

Posting Permissions

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



Click Here to Expand Forum to Full Width