note 99399 deleted from function.curl-setopt by levim

From: Date: Mon, 24 Feb 2014 23:02:34 +0000
Subject: note 99399 deleted from function.curl-setopt by levim
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-198689@lists.php.net to get a copy of this message
Note Submitter: daniel at blacklotus dot no ---- 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"); ?>

« previous php.notes (#198689) next »