curl-and-php
Using POST and POSTFIELDS with CURL
Date: Mon, 24 Dec 2007 10:09:08 -0500
Hi.
I am having trouble getting CURL to return the results of clicking a button on a partcular page of a website that I am interested in. The PHP script is as follows :
<?php
$url = "http://www.0044.co.uk/Tariffs/Global/calculate-ekit.asp?Action=compute";
$postfields = "selectOrigination=AFG&selectDestination=GBR&selectCurrency=EUR&myOrig=&myDest=&imageField.x=5&imageField.y=5";
$ch = curl_init();
$randnum = rand(1,9999999);
curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookiejar-$randnum");
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookiejar-$randnum");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$data = curl_exec($ch);
curl_close($ch);
echo "DATA = ";
$content1 = gettextonly($data);
echo $content1;
function gettextonly($in)? {
??????? $search = array("@<script[^>]*?>.*?</script>@si",?????? // Strip out javascript
??????? "@<style[^>]*?>.*?</style>@siU",??????????????????????? // Strip style tags properly
??????? "@<[\/\!]*?[^<>]*?>@si",??????????????????????????????? // Strip out HTML tags
??????? "@<![\s\S]*?-[ \t\n\r]*>@",???????????????????????????? // Strip multi-line comments including CDATA
??????? "/\s{2,}/",
??????? );
??????? $text = preg_replace($search, "\n", html_entity_decode($in));
??????? $pat[0] = "/^\s+/";
??????? $pat[2] = "/\s+\$/";
??????? $rep[0] = "";
??????? $rep[2] = " ";
??????? $textonly = preg_replace($pat, $rep, trim($text));
??????? return $textonly;
}
?>
The string for the POSTFIELDS option was derived by looking at what really happens when someone uses the site, by examining the detail in the Mozilla add-on HTTP Live Headers.
Regards
Tony Pieretti
________________________________________________________________________
AOL's new homepage has launched. Take a tour at http://info.aol.co.uk/homepage/ now.
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2007-12-24