Page 1 of 1
Adding POST data to a redirect?
Posted: Fri May 02, 2003 1:54 pm
by andrewcarraway
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
You can do it with javascript
Posted: Fri May 02, 2003 2:23 pm
by pascalganaye
I don't know if it helps,
I wanted to login in phpbb without displaying the form.
I managed to do it this way :
Code: Select all
$HTTP_POST_VARSї'username'] = $username;
$HTTP_POST_VARSї'login'] = "Connexion";
$HTTP_POST_VARSї'redirect'] = "";
$HTTP_POST_VARSї'autologin'] = "false";
$password = $row->password;
$HTTP_POST_VARSї'password'] = $password;
chdir("../phpBB2/");
include('login.php');
This does a fake redirect with forced POSTED values
Posted: Fri May 02, 2003 2:24 pm
by andrewcarraway
Maybe I wans't very clear... here is some more information:
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
Pretty simple stuff...
Posted: Fri May 02, 2003 2:26 pm
by Jim
Grab the information from the POST like so:
Code: Select all
$linkname = $_POST['name_of_field_you_are_entering_info_in'];
header ("Location: http://www.yoursi.te/$linkname");
Posted: Fri May 02, 2003 2:26 pm
by andrewcarraway
Thanks for the example above. My problem is that I am sending this information to a third party, not located on my server, so I can't make any changes to the code or include anything on their server.
Andrew
Posted: Fri May 02, 2003 2:27 pm
by andrewcarraway
Okay, I'll try that.
Posted: Fri May 02, 2003 2:35 pm
by andrewcarraway
That didn't work either.
Posted: Fri May 02, 2003 2:37 pm
by Jim
Hmm... the example I gave you won't work unless you actually use a form to transmit the data. And since you can't change the code on this other server anyway, you wont' be able to adjust the code to do what you want it to.
Even if you could send information as if you had POSTed it, the page you're sending the information to has to be set up to receive the information.
Chances are, since you aren't editing the script, it's not set to do that. Why in the world are you trying to access a script you don't have control of anyway?
Posted: Fri May 02, 2003 2:44 pm
by pascalganaye
You could perhaps generate a page who will post automatically the value you want to post :
Code: Select all
<body onload="javascript:document.form1.submit();">
<form action="http://ww.otherserver.com/post.php?xx=4&yy=2" method="post" name="form1">
<input name="value1" type="hidden" value="0">
<input name="value2" type="hidden" value="1">
</form>
Posted: Fri May 02, 2003 2:46 pm
by andrewcarraway
We are integrating our shopping cart system with a third party. They need the information sent through a form, but before we send it along, I need to capture it and process it. (I don't know why they do it that way, but they just do and I have to figure out a way to deal with it.)
It doesn't look like there is any way to do this, at least nobody seens to know. I have done something similar in ASP, where you add the POST data to the header of the redirect... but it doesn't look like there's a way to do that in PHP.
Andrew
Posted: Fri May 02, 2003 2:49 pm
by andrewcarraway
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
Posted: Fri May 02, 2003 4:02 pm
by hedge
Maybe this should be a sticky, it seems like I am providing this link every week.
At the bottom is some code I posted with some functions to simulate a post
viewtopic.php?t=7063