Guest Posted June 27, 2012 Report Posted June 27, 2012 O functie foarte utila pentru a usura lucrul cu curl, se salveaza intr-un fisier de exemplu curl.php si se include in fisierul php de lucru.Se creaza folderul "cookies" unde vor fi stocate cookies pentru fiecare utilizator unic in parte , astfel evitam amestecarea lor (initial am pus sa salveze cookie in forma ip.txt - gen 127.0.0.1.txt dar cum multi provideri de internet pe mobil foloseau acelasi ip .... se amestecau).<?phpif (!isset($_SESSION)) { session_start();}$config['useragent'] = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0.1";$config['cookie_file'] = "./cookies/".session_id();$config['proxy'] = "";$config['proxy_port'] = "";function curl($url='',$var=''){ global $config; $curl = curl_init(); if (isset($config['proxy'])) { curl_setopt($curl, CURLOPT_HTTPPROXYTUNNEL, true); curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); curl_setopt($curl, CURLOPT_PROXY, $config['proxy']); curl_setopt($curl, CURLOPT_PROXYPORT, $config['proxy_port']); } curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl,CURLOPT_CONNECTTIMEOUT,20); curl_setopt($curl, CURLOPT_USERAGENT, $config['useragent']); curl_setopt($curl, CURLOPT_REFERER, "http://google.com/"); if($var) { curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $var); } curl_setopt($curl, CURLOPT_COOKIE,''.$config['cookie_file']); curl_setopt($curl, CURLOPT_COOKIEFILE,''.$config['cookie_file']); curl_setopt($curl, CURLOPT_COOKIEJAR,''.$config['cookie_file']); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 3); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); $result = curl_exec($curl); curl_close($curl); return $result;}?>Iar functia functioneaza cam asa:<?phpset_time_limit(3600);include("curl.php");if(!file_exists($config['cookie_file'])){ $fp = @fopen($config['cookie_file'],'w'); @fclose($fp);} $url = "http://google.com/login.php"; $var = "var1=9928727&var2=913891731"; $result = curl($url,$var); echo $result;?>Acest exemplu face POST la variabile, dar daca aveti nevoie de GET folositi : $result = curl($url); Quote
caramea Posted June 27, 2012 Report Posted June 27, 2012 Eu incerc sa tot fac o autentificare prin cURL la m.yahoo.com, dar nu-i dau deloc de capat. Quote
Irk Posted June 28, 2012 Report Posted June 28, 2012 folositi guzzle, pentru ca nu mai suntem in anii 90. Quote
SilviuSDS Posted June 28, 2012 Report Posted June 28, 2012 folositi guzzle, pentru ca nu mai suntem in anii 90.Si cat de multe inveti cand iei o treaba gata facuta? Quote