note 99399 added to function.curl-setopt
| From: | daniel at blacklotus dot no | Date: | Sun, 15 Aug 2010 12:33:17 +0000 |
| Subject: | note 99399 added to function.curl-setopt | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-171688@lists.php.net to get a copy of this message | ||
Sime sites may protect themselves from remote logins by checking which site you came from.
Then you might want to use CURLOPT_REFERER.
<?php
// $url = page to POST data
// $ref_url = tell the server which page you came from (spoofing)
// $login = true will make a clean cookie-file.
// $proxy = proxy data
// $proxystatus = do you use a proxy ? true/false
function
curl_grab_page($url,$ref_url,$data,$login,$proxy,$proxystatus){
if($login == 'true') {
$fp = fopen("cookie.txt", "w");
fclose($fp);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT
5.0)");
curl_setopt($ch, CURLOPT_TIMEOUT, 40);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
if ($proxystatus == 'true') {
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
}
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $ref_url);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
ob_start();
return curl_exec ($ch); // execute the curl command
ob_end_clean();
curl_close ($ch);
unset($ch);
}
echo curl_grab_page("https://www.example.net/login.php",
"https://www.example.net/",
"username=foo&password=bar", "true", "null", "false");
?>
----
Server IP: 85.19.212.230
Probable Submitter: 84.202.151.245
----
Manual Page -- http://www.php.net/manual/en/function.curl-setopt.php
Edit -- https://master.php.net/note/edit/99399
Del: integrated -- https://master.php.net/note/delete/99399/integrated
Del: useless -- https://master.php.net/note/delete/99399/useless
Del: bad code -- https://master.php.net/note/delete/99399/bad+code
Del: spam -- https://master.php.net/note/delete/99399/spam
Del: non-english -- https://master.php.net/note/delete/99399/non-english
Del: in docs -- https://master.php.net/note/delete/99399/in+docs
Del: other reasons-- https://master.php.net/note/delete/99399
Reject -- https://master.php.net/note/reject/99399
Search -- https://master.php.net/manage/user-notes.php