PHP question about form POST data

Soldato
Joined
18 Oct 2002
Posts
3,245
Location
melbourne
I'm a novice with PHP but really enjoying it so far.

I want to execute some PHP code and then send the user to another site with POST data. At the moment, the user has to click on the Submit button in a form to send POST data. Is there anyway this can be done automatically with PHP?

This is what I have currently:


PHP:
<?php
(execute php code)
?>


<form action="anotherScript.php" method="post">
<input type=hidden name="someName" value="someValue">
<input name="submit" type="submit" value="Click here to continue"  />
</form>

What I would like to do:

PHP:
<?php
(execute php code)

(send user automatically to anotherScript.php with POST data)
?>

Thanks for the help.
 
if I read that correctly

execute PHP code using Post data

Stick POST data into a session

Direct user to another script.php and run that with the Session containing the orginal POST?

May be wrong but that's my initial idea
 
You can post the data to another site using php/CURL

PHP:
$url = "http://www.otherwebsite.com/inbound.php";
$params = "Field_1=one&Field_2=2";
$variable=$_POST['variable_name']
$user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";

$connection = curl_init();
curl_setopt($connection, CURLOPT_POST,1);
curl_setopt($connection, CURLOPT_POSTFIELDS,$params);
curl_setopt($connection, CURLOPT_URL,$url);
curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($connection, CURLOPT_USERAGENT, $user_agent);
curl_setopt($connection, CURLOPT_RETURNTRANSFER,1);
curl_setopt($connection, CURLOPT_VERBOSE, 1); //for debugging purposes
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, FALSE); // this line makes it work under https

$result=curl_exec ($connection);
echo("Results: ".$result); // debugging purposes

This will pass the data over and the echo will bring back the result.

I can't find a solution that would allow you to pass POSTS on a redirect, the only alternative would be to use Javascript to submit the form automatically.

Personally I'd use the second page as an opportunity for the user to check the data they are about to submit or go back to correct.
 
Back
Top Bottom