note 29769 deleted from function.curl-setopt by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 May 2009 17:34:35 +0000 |
| Subject: | note 29769 deleted from function.curl-setopt by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155001@lists.php.net to get a copy of this message | ||
Note Submitter: joeldegan AT yahoo.com
----
Often times people ask about how to get data from secure servers.
Here is an example of getting the balance page from Paypal
<?
# script by Joel De Gan
# http://listbid.com
function GetCurlPage ($pageSpec) {
$agent = "up.b";
$header[] = "Accept: text/vnd.wap.wml,*.*";
$ch = curl_init($pageSpec);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1); ########### debug
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt ($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cook");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cook");
$tmp = curl_exec ($ch);
curl_close ($ch);
return $tmp;
}
function PostCurlPage ($pageSpec, $data) {
$agent = "up.b";
$header[] = "Accept: text/vnd.wap.wml,*.*";
$ch = curl_init($pageSpec);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1); ########### debug
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt ($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cook");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cook");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$tmp = curl_exec ($ch);
curl_close ($ch);
return $tmp;
}
$first = GetCurlPage("https://www.paypal.com/cgi-bin/phscr?cmd=login");
$exp = explode("=", $first);
$id = explode("\"", $exp[16]);
$second = PostCurlPage("https://www.paypal.com/cgi-bin/phscr?rs=".$id[0],
"email=EMAIL@HOST.COM&pass=YOUR_PP_PASS&cmd=login-submit-pass");
echo $second."\n\n";
?>