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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

POST via PHP Server redirect 1

Status
Not open for further replies.

mhamilton3

Programmer
Oct 31, 2001
129
Hello,
I am wondering if there is a way to post variables when redirecting with PHP. I know I can use
Code:
header("Location: [URL unfurl="true"]http://...?whatever=something")[/URL]
but I want to post whatever so it does not appear on the URL when calling the subsequent page. I have looked through a whole bunch of documentation (including tek-tips faqs) and I can not find a solution. Thanks for whatever help you can lend me.
 
You've run into the limits of HTTP.

POST-method variables are sent to the web server via HTTP headers, and so are part of the request a browser sends to a server. There's no way to both redirect a browser and force it to send data.

You might try having PHP send an interim page that contains a form the action of which is the foreign script. Include your data in hidden variables and JavaScript to automatically submit the form.

You also might try using PHP's cURL libraries to post the data to the foreign script, retrieve the return from the foreign server, and send the return to the user's browser.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thank you very much sleipnir214. I had a feeling what I was trying to do was impossible, but I could not figure out why.

I would have though there was a way to act as a browser and format the HTTP headers to appear to be coming from a browser. I suppose there are probably some security issues with that approach which is why it does not exist.

Thanks again.
 
There is a way to programmatically act as a web browser from within a PHP script -- use PHP's cURL libraries. PHP would send the data to the foreign server, fetch the return information from the foreign server and forward that return to the browser.

But if you send a browser a "Location:" header, the browser ends the connection immediately and performs a call to the URL pointed to in the header. There is no way for a server to send data to a foreign server then somehow connect the return to a browser through a redirect -- sort of "intercepting" the action of the browser. That runs into the limits of TCP/IP.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top