« Find the files not in use in Unix | Home | MD5 function for encrypting a string in VB.NET »
HTTP POST request with PHP CURL
switch($_REQUEST['cmd']){
default:
include 'form.html';
break;
case "post":
$postfields = array();
$postfields[] = array("firstname", $_POST['firstname']);
$postfields[] = array("lastname", $_POST['lastname']);
$postfields[] = array("ccnumber", $_POST['ccnumber']);
$postfields[] = array("expmonth", $_POST['expmonth']);
$postfields[] = array("expyear", $_POST['expyear']);
foreach($postfields as $subarray) {
list($foo, $bar) = $subarray;
$bar = urlencode($bar);
$postedfields[] = "$foo=$bar";
}
$urlstring = join("n", $postedfields);
$urlstring = ereg_replace("n", "&", $urlstring);
// echo $urlstring;
$ch = curl_init("http://mysite.com/curl/curlresponse.php");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $urlstring);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_REFERER, "http://www.mysite.com/payment_form.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
$response_start = strPos($data, "Server Response:");
$response_end = strPos($data, "n");
$temp_code = substr($data, $response_start, ($response_end - $response_start));
$temp_code = str_replace("Server Response:", "", $temp_code);
$temp_code = strip_tags($temp_code);
$transaction_code = trim($temp_code);
switch($transaction_code){
case "Transaction Success!":
//redirect person to thank you page
echo "Thank you for your purchase!";
break;
default:
echo 'Transaction Error: '.$transaction_code.'';
include 'form.html';
break;
}
break;
}
?>
Topics: Curl, PHP | Submitter: admin
3 Responses to “HTTP POST request with PHP CURL”
Comments
You must be logged in to post a comment.
February 13th, 2006 at 3:53 pm
The name of the post publisher should be displayed somewhere on the page. We are living in the nice time of user communities, anyway...
February 13th, 2006 at 4:53 pm
alrighty
February 13th, 2006 at 6:35 pm
Additionally, I think, some kind of discussion board/forum is necessary (only for registered users, probably). In this case we could avoid writing such messages to the post about PHP :-)