operat0r_001 Posted September 4, 2007 Share Posted September 4, 2007 :: Fixed the code :: Example cURL ( libcurl) code with debug option. <?php /* change the LOGINEMALHERE%40yahoo.com /* change the PASSWORDHERE /* then run it ! php snort.php > snortrules-snapshot-2.4.tar.gz /* set both DEBUG_ options to true to debug ... define(DEBUG_PRINT, FALSE); define(DEBUG_MODE, FALSE); error_reporting(E_ALL | E_STRICT); $my_mundo_travian = 'http://www.snort.org'; $my_login_url = "$my_mundo_travian/login/"; /* below the original test page has a string with valid header data copied as shown in the tutorial using live http headers */ $my_login_data = "destination=https%3A%2F%2Fwww.snort.org%2Freg-bin%2Fuserprefs.cgi&credential_0=LOGINEMALHERE%40yahoo.com&credential_1=PASSWORDHERE&Submit=login+to+snort.org"; $my_proxy = ''; $my_proxy_status = 'off'; /* after a successful login, this url shows the initial game control panel. If login fails, it shows the login page */ $my_grab_page = 'http://www.snort.org/pub-bin/downloads.cgi/Download/vrt_os/snortrules-snapshot-2.4.tar.gz'; $fp_err = fopen("curl_errors.txt", "w"); curl_login($my_login_url, $my_login_data, $my_proxy, $my_proxy_status); echo curl_grab_page($my_grab_page, $my_proxy, $my_proxy_status); fclose($fp_err); /* login functions by Chad from http://codersshack.com/forums/php_11/tutorial-curl-login_44.html */ /* functions are slightly modified in order to send curl verbose report to a file */ function curl_login($url,$data,$proxy,$proxystatus){ global $fp_err; $fp = fopen("cookie_travian.txt", "w"); fclose($fp); $login = curl_init(); if (DEBUG_MODE) { curl_setopt($login, CURLOPT_VERBOSE, TRUE); curl_setopt($login, CURLOPT_STDERR, $fp_err); } curl_setopt($login, CURLOPT_COOKIEJAR, "cookie_travian.txt"); curl_setopt($login, CURLOPT_COOKIEFILE, "cookie_travian.txt"); curl_setopt($login, CURLOPT_USERAGENT, "rmccurdy"); curl_setopt($login, CURLOPT_REFERER, "http://www.snort.org/pub-bin/downloads.cgi/Download/vrt_os/"); curl_setopt($login, CURLOPT_TIMEOUT, 30); curl_setopt($login, CURLOPT_RETURNTRANSFER, TRUE); if ($proxystatus == 'on') { curl_setopt($login, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($login, CURLOPT_HTTPPROXYTUNNEL, TRUE); curl_setopt($login, CURLOPT_PROXY, $proxy); } curl_setopt($login, CURLOPT_URL, $url); curl_setopt($login, CURLOPT_HEADER, TRUE); curl_setopt($login, CURLOPT_USERAGENT, "rmccurdy"); curl_setopt($login, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($login, CURLOPT_POST, TRUE); curl_setopt($login, CURLOPT_POSTFIELDS, $data); ob_start(); // prevent any output return curl_exec ($login); // execute the curl command ob_end_clean(); // stop preventing output curl_close ($login); unset($login); } function curl_grab_page($site,$proxy,$proxystatus){ global $fp_err; $ch = curl_init(); if (DEBUG_MODE) { curl_setopt($ch, CURLOPT_VERBOSE, TRUE); curl_setopt($ch, CURLOPT_STDERR, $fp_err); } curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); if ($proxystatus == 'on') { curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE); curl_setopt($ch, CURLOPT_PROXY, $proxy); } curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie_travian.txt"); curl_setopt($ch, CURLOPT_URL, $site); ob_start(); // prevent any output return curl_exec ($ch); // execute the curl command ob_end_clean(); // stop preventing output curl_close ($ch); } if (DEBUG_PRINT) { echo "<br>COOKIE<br>"; $file = file_get_contents ('cookie_travian.txt'); Echo $file; echo "<br>ERR<br>"; $file = file_get_contents ('curl_errors.txt'); Echo $file; } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.