how to redirect PHP $_POST request from page1 -> page2 -> page3?

stndn

Golden Member
Mar 10, 2001
1,886
0
0
Here's the situation:
I have three PHP pages, i'll call them page1.php, page2.php, page3.php

page1.php basically contains basic HTML Form where user enter their login and password, and on SUBMIT will send the request to page2.php as POST request.

page2.php gets the $_POST values from page1.php, do some magic stuff to the $_POST values sent by page1.php, then redirect the end result to page3.php

page3.php print the result from page2.php.


Now, the problem is:
I want the magic data from page2.php to be sent to page3.php as a POST request automatically. So, if i do print_r ($_POST) on page3.php, i'll get the list of all $_POST values.

How do I do the redirect from page2.php to page3.php and keep it as POST?
I tried header ("Location: page3.php");, but that sends the redirection as $_GET request and not $_POST request.


Thanks.
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
I'm not sure if this is the best way, but couldn't you just set them as session variables on page2 then once page3 loads just use the session variables? Or you could even go so far as to copy them to the correct post entries.
 

Drakkon

Diamond Member
Aug 14, 2001
8,401
1
0
i dont get why the 2nd page is in there...i mean why not just "include" the 2nd or 3rd page?
what is the 2nd page doing that it can't be handled on the third page?

The roundabout way to do it would be to have the page load all the post variables into "hidden" input fields and then through javascript after the body loads sumbit the page again to the third page, that would be kinds redundant though :p
 

stndn

Golden Member
Mar 10, 2001
1,886
0
0
To clarify,
page1.php resides on our site, where the user will enter their information.
when they click on submit, we want to run page2.php in the background to process user's information, and then send the data as $_POST request to an external site not on our system.
The external script (page3.php) requires us to send data as $_POST data, so we'll need to redirect it as such to them.

Confusing?
Yah... i know ....

Good news though, my coworker is going to hint me on how to accomplish that, so hopefully that will get done soon -)

Thanks.
 

mugs

Lifer
Apr 29, 2003
48,920
46
91
:thumbsup: to session. :thumbsdown: to GET. If it's absolutely imperitive that it be through a POST, you could use a loop to output the post array to hidden fields and use javascript to submit the form on page load... but that falls apart if the user does not have javascript enabled. You could craft the HTTP request yourself probably... but that's going a bit overboard. Or you could just use session. If it makes you feel better, you could store the whole POST array in $_SESSION["POST"] :)

Edit: just saw you say the third page is an external script that you apparantly have no control over. In that case, it seems that the javascript idea would be your best solution, but put a submit button on the page that says something to the effect of "click here to continue" just in case they don't have javascript
 

Red Squirrel

No Lifer
May 24, 2003
70,391
13,697
126
www.anyf.ca
Another solution is to have it go in hidden fields name properly to reflect the ones on page3, and simply have the user hit a submit button, so they login, and get to a page that says "click this button to continue" and then it would submit, you could throw in some js to do it automaticly but keep the button so that if they have it disabled they see the message and click it manually. On this page you can also warn them that they are being sent to a different site. (not a bad idea to let them know)
 

stndn

Golden Member
Mar 10, 2001
1,886
0
0
Thanks for the replies.
Problem is, we cannot let users see page2.php because they contain confidential information that needs to be sent along to page3.php which resides outside our server. So, we cannot display the page and have it submit hidden field because if the user view source, they'll get our account information.

And $_SESSION is out since .. well, it's outside our server.

Anyways, talked to a co-worker, and he mentioned I need to send a custom POST header in order to accomplish what I wanted. and that's what i'll end up doing.

Thanks -)
 

azollman

Junior Member
May 26, 2001
20
0
0
I had this problem for a while with an external site, and had all of these things suggested.

Eventually, I wound up using the cURL libraries which basically allowed me to craft the HTTP header, but did most of the hard work. There's a function within cURL to allow sending post variables. I don't remember exactly, but if you can enable the cURL libraries within PHP, you might find that it does what you need.

Good luck.
az
 

Syran

Golden Member
Dec 4, 2000
1,493
0
76
I actually have to do a little of this as well. Where I work, we have a support ticket system that sends a message to the technicians cell phones with the information needed.

What I ended up doing was using an iframe, with an automatic javascript submit, and a hidden form.