I am trying to redirect a page using header("Location: [URL]");

I would like to add POST data to the redirect, in other words, I want to send information to along to the next page as if I had submitted it to that page in a form. Any ideas?

Thanks!

Andrew

    can you show us some code with an example of what you are really trying to do

      That's just my problem... I don't know how to do this so I haven't tried anything yet.

      I want to send information to a redirected page via POST. I can do it via GET by tagging all the information to the url in the querystring, like this:

      header("Location: sample.php?test=true");

      (In this example I am sending the paramater of 'test' with the value of 'true'.)

      My problem is that the page I am trying to redirect to will not accept data that is sent through the GET method. It will only accept POST, so I am asking if anyone knows how to add the POST data to the redirect, as if I had sent the information by submitting a form.

      Thanks again,

      Andrew

        is there any particular reason that the page won't accept $_GET methods

          Suppose you have an input in form like this:

          <input type=radio name="test" value="true">

          If this button is checked, and submitted, $_POST['test']="true", therefore it would be:

          header ("location: sample.php?test=$_POST['test']");

            The page I am trying to redirect to is actually a third party we are working with, so I have no control over whether it accepts GETs.

            I have tried the above example, but it doesn't work... it still recognizes the querystring as a GET.

              k, so let me get this straight, you have page_a.php which is a form page that posts to page_b.php, which you then want to redirect to the page_third_party.php and post the variables to that? am i on the right track, and if so, why don't you simply post straight to that page_third_party.php

                When the information is submitted, I need to process it on my server (store it in mysql, get a timestamp, and run a function that generates a unique identifier -this is part of a shopping cart system). After it is processed, I need to send the modified information on to the 3rd party.

                  ok, get rid of your header(Location๐Ÿ™‚ thinking and do it this way, simply put the necessary information into hidden form fields and then let javascript automatically submit the form to the third party page

                  put this in your head and then use the form

                  <SCRIPT LANGUAGE="JavaScript"><!--
                  setTimeout('document.formname.submit()',5000);
                  //--></SCRIPT>

                  this will submit after 5 seconds, i'm sure you can figure out the time if you want it less

                  can you do it this way //yes, no, maybe

                    Thanks for all your help, but I'm afraid in this case a workaround will not be acceptable. If there's not a way to directly tag the post data on to a redirect, I'll have to maybe switch to ASP. Thanks again for all your help!

                    Andrew

                      why doesn't that work, i don't understand, instead of redirecting with post data to the third party page, you simply use javascript to post it there, i am pretty sure there isn't gonna be a way to to it with a Response.Redirect in ASP either

                        Sorry, I misunderstood your suggestion. Yeah, that would probably do the trick. I would still prefer a PHP solution than JavaScript, but if I can't figure out a way to do it directly I might have to go that way.

                        Thanks again for the help!

                        Andrew

                          yeah i have tried to do this before, but you are really limited with PHP's header redirect, good luck and if you need some help with the js way lemme know

                            I have the same problem listed above. Here is the real world issue:

                            Shopping cart for Authorize.net. Collect all the details, sending them in a form, as post, is not a problem. The problem is that Authorize net wan'ts me to send my user name and password with this. Now the user name and password would let someone log in and edit transactions etc.

                            So if I just append this to the form as a hidden field, there is the possibility of a security compromise. Therefore I need to find a way to do this.

                            I have gone through a ton of books, searched online for a variety of keywords, and now am pulling out what little remaining hair I have!

                            Any help with this would be very very very greatfuly recieved!

                            John Smart

                              How do Authorize.net expect you to do it? I'm sure they wouldn't want you to be sticking your username and password to their service in your form...

                              What sort of transaction details is the user supposed to be able to edit (after placing their order)? I only glanced at their web site, but from what I did look at, the user isn't supposed to see authorize.net's stuff - they're supposed to see your site. While you get to examine your account with authorize.net and edit transaction details yourself. (I had this nasty picture of someone logging in after making a purchase and giving themselves big discounts.)

                              Okay; this isn't a redirect method. Instead, your server acts as a proxy between the user and authorize.net. Dunno what authorize.net sends back as a result of the form submission and what if anything you'll need to do with it; their documentation should cover that. But seeing as you'll probably be wanting to send POST forms to authorize.net, you've got two options.

                              1) Use [man]fsockopen/man to create an http connection to authorize.net, and write the POST request by hand and send it. Pros: much more likely to be supported by your build of PHP. Cons: a bit more tedious
                              2) Use the cURL functions to build and send the request. Pros: less low-level protocol stuff; Cons: you might not have cURL installed.

                              You may possibly work the proxy the other way, but taking authorize.net's responses and feeding them back to the user, but that's sounds highly unstable to me (for one thing, it would break every relative URL on the page).

                                Thank you!
                                This is wonderful - and an example too! I am working through this and will post how I do.

                                My concern is handling the responce, but I am not quite there yet!

                                Thank you both for your time, I am very apreciative.

                                Kindest regards,

                                John Smart

                                  I set up the script suggested above, changed it to https (by placing "ssl:/" between "Host:" and "$server") and got no response.

                                  I am using a snippet of code that will echo back any POSTed fields that are sent to my script, and it is all blank.

                                  I added socket_set_timeout to give Authorize.net time to respond. In writing this, I know what the problem is, but not how to get around it. The problem is how do I collect what is sent back? Of course I cannot see it as POSTed to the script, for the script has been called, and will not add a response to the posted data after the fact. So Authorize.net sends back the results to a URI that I define. Should it be to a different one> How do I then porogress on to that to read it?

                                  My best answer at this time is to have a responce URI that grabs the data (as post, as it will be calling afresh) and sets it to an SQL entry. Then the page that sent the request could have a timed header/location taking it to a page that reads the SQL entry and works accordingly.

                                  What a mess, that could not be less elegant!

                                  Authorize net sends the responce encapsulated in my choice of characters with my choice of seperator, to a URI of my choosing (the same as the sending one or a different one).

                                  How would I get that? Using fopen through fsocks? I am more than a little over my head here! Any suggestions would be greatfully recieved,

                                  John

                                    Okay, it is possible to integrate php with AIM!

                                    A lot of work, and numerous circles have lead to the following discoveries:

                                    1. You CANNOT use AIM with the header (); command.
                                    2. You Almost certainly cannot link to AIM with fsock.
                                    3. You CAN do it with cURL!
                                      You need to reinstall PHP with cURL (not my area, so I won't confuse by saying how). Then you can use something similar to:

                                    $curl_fields="x_Version=3.1&";
                                    $curl_fields.="$curl_fields.=x_Login=[USERNAME]&";
                                    $curl_fields.="x_Password=[PASSWORD]&";
                                    $curl_fields.="x_Amount=$total";
                                    Etc...

                                    $ch=curl_init("https://secure.authorize.net/gateway/transact.dll");
                                    curl_setopt($ch, CURLOPT_HEADER, 0);
                                    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
                                    curl_setopt($ch, CURLOPT_USERAGENT, "ID Cart");
                                    curl_setopt($ch, CURLOPT_POSTFIELDS, $curl_fields);
                                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                                    $response = curl_exec($ch);
                                    curl_close($ch);
                                    $delimit ="=".$x_Delim_Char."=";
                                    $response_details=explode($delimit,$response);

                                    From the $response_details array you will be able to get the response (approved/failed), and the reason for failure as well as all the other fields that it is set to return to you.

                                    You do NOT need to set the port number (even though cURL allows that) because you are sending to and from an https.

                                    I apologize if this is too simple for the most of you here, but had I known this a week or so ago I wouldn't be quite as bald as I currently am!

                                      Write a Reply...