Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redirect with POST 2

Status
Not open for further replies.

RobBroekhuis

Technical User
Oct 15, 2001
1,971
US
I've done the header("location: ...") thing many a time for a simple redirect. Now I'm looking for a way to have php do some preprocessing, change the POST data, and then redirect to a different url as a POST. How would I go about that?

Rob
[flowerface]
 
I don't think you can do a redirect with post data from the server side.

You can have PHP on your server interact with the foreign server and then display information from that server to the user's browser. This is useful, for example, for credit-card processing in an e-commcerce site.



Want the best answers? Ask the best questions! TANSTAAFL!
 
The only think to watch out for is output. You cannot send anything out, before issuing the redirect, that icnludes html, echo statements, doctype info etc.

As long as your PHP code is the first thing on the page that will redirect, and as long as it does not output anything. The redirect shoud work fine.

If you want to modify the POST data do all the changes and the construct your URL for the redirect something like:



Code:
$somevariable=$_POST['mypostvar'];
$mylocation="someotherpage.php?value1=". $somevariable . "&value2=" . $someotherVariable;

and then just issue the header location command.
The values will now be available in the $_GET superglobal.
from the new location.

Or you can alternatively put the new values into session variables, whcih can then be accessed in the new location.




----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks for your reply. You mean php cannot do everything any ol' client-side browser can? I can perform the post just fine using the PHP/curl library - but of course then I get the response from the external server back to my server-side script, instead of to my user's browser.
I've read about doing redirects with 307 http status codes to PRESERVE the posted data - I would have thought there's an equivalent way to modify data before redirecting. If not, it's just an extra button click for my users. But I'm still hoping to avoid that.

Rob
[flowerface]
 
Thanks Vacunita - that would work grand if the url to which I'm redirecting expects GET data - but it expects POST data, and I haven't yet figured out how to send that in a redirect through php (assuming that it can be done, which I'm now doubting, based on Sleipnir's reply).

Rob
[flowerface]
 
but of course then I get the response from the external server back to my server-side script, instead of to my user's browser.
That's exactly what happens when I use cURL to make a "backend" connection to a credit-card processing house during an e-commerce sale. Once my script receives the data (via cURL) from the credit-card processor, it tweaks the look-and-feel, records what it needs to, and displays parts of the data to the user.



Want the best answers? Ask the best questions! TANSTAAFL!
 
Thank you both for helping out. Vacunita, that snippet helps me understand how a POST request header is formatted, which is very helpful. Thinking about it some more, it has also become obvious to me that what I wanted to do (sending a response header to go ask the client to post some data of my choosing elsewhere) is a security nightmare, and wouldn't/shouldn't be allowable. So I'll forget about this avenue - but I've learned a few new things :)

Rob
[flowerface]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top