Adding POST data to a redirect?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
andrewcarraway
Forum Newbie
Posts: 9
Joined: Fri May 02, 2003 1:54 pm

Adding POST data to a redirect?

Post 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
pascalganaye
Forum Newbie
Posts: 3
Joined: Fri May 02, 2003 2:10 pm
Location: BATH - UK
Contact:

You can do it with javascript

Post 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
andrewcarraway
Forum Newbie
Posts: 9
Joined: Fri May 02, 2003 1:54 pm

Post 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
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Pretty simple stuff...

Post 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");
andrewcarraway
Forum Newbie
Posts: 9
Joined: Fri May 02, 2003 1:54 pm

Post 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
andrewcarraway
Forum Newbie
Posts: 9
Joined: Fri May 02, 2003 1:54 pm

Post by andrewcarraway »

Okay, I'll try that.
andrewcarraway
Forum Newbie
Posts: 9
Joined: Fri May 02, 2003 1:54 pm

Post by andrewcarraway »

That didn't work either.
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Post 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?
pascalganaye
Forum Newbie
Posts: 3
Joined: Fri May 02, 2003 2:10 pm
Location: BATH - UK
Contact:

Post 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>
andrewcarraway
Forum Newbie
Posts: 9
Joined: Fri May 02, 2003 1:54 pm

Post 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
andrewcarraway
Forum Newbie
Posts: 9
Joined: Fri May 02, 2003 1:54 pm

Post 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
hedge
Forum Contributor
Posts: 234
Joined: Fri Aug 30, 2002 10:19 am
Location: Calgary, AB, Canada

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