php - Login and fetch a protected page with cURL -
i got login part of script working second part not work.
<?php // curl login $login = "http://****/admin/index.php?route=common/login"; $credentials = "username=admin&password=****"; $cookie = "cookie.txt"; $ch = curl_init(); curl_setopt ($ch, curlopt_url, $login); curl_setopt ($ch, curlopt_post, 1); curl_setopt ($ch, curlopt_postfields, $credentials); curl_setopt ($ch, curlopt_cookiejar, $cookie); curl_setopt ($ch, curlopt_returntransfer, 1); $exec = curl_exec ($ch); // logged in, fetch post data $url = $_post['order']; $return = $_post['return']; // request protected invoice page curl_setopt($ch, curlopt_header, 0); curl_setopt($ch, curlopt_verbose, 0); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt ($ch, curlopt_useragent, "mozilla/5.0 (windows; u; windows nt 5.1; en-us; rv:1.8.1.6) gecko/20070725 firefox/2.0.0.6"); curl_setopt($ch, curlopt_url, $url); $response = curl_exec($ch); curl_close($ch); $headers = 'mime-version: 1.0' . "\r\n"; $headers .= 'content-type: text/html; charset=iso-8859-1' . "\r\n"; // mail mail('****@gmail.com', 'invoice', $response, $headers); // dump var_dump($response); ?>
now if provide wrong credentials mailed admin login page login errors if provide correct credentials nothing empty email. var_dump
@ end of script returns string(0)
.
the $url = $_post['order'];
accessible , it's correct url if logged in administration returns order invoice page.
should reinitialize curl after trying fetch protected page. first login > close curl reinitialize , fetch page or did miss option ?
my reiteration:
<?php // curl login $login = "http://***/admin/index.php?route=common/login"; $credentials = "username=***&password=***"; $cookie = "cookie.txt"; // initialize $ch = curl_init(); curl_setopt ($ch, curlopt_url, $login); curl_setopt ($ch, curlopt_postfields, $credentials); curl_setopt ($ch, curlopt_post, 1); curl_setopt ($ch, curlopt_cookiejar, $cookie); curl_setopt ($ch, curlopt_cookiefile, $cookie); curl_setopt ($ch, curlopt_followlocation, 1) curl_setopt ($ch, curlopt_returntransfer, 1); curl_setopt ($ch, curlopt_ssl_verifypeer, false); curl_setopt ($ch, curlopt_useragent, "mozilla/5.0 (windows; u; windows nt 5.1; en-us; rv:1.8.1.6) gecko/20070725 firefox/2.0.0.6"); curl_setopt ($ch, curlopt_header, 0); curl_setopt ($ch, curlopt_verbose, 0); // login - use $exec = curl_exec ($ch); // logged in, fetch post data $url = $_post['order']; $return = $_post['return']; // request protected invoice page curl_setopt($ch, curlopt_url, $url); $response = curl_exec($ch); echo '<br /><br />-----------------------------------------------------------------------------------------------------------------<br /><br />'; var_dump($response); echo '<br /><br />-----------------------------------------------------------------------------------------------------------------<br /><br />'; var_dump(curl_getinfo($ch)); echo '<br /><br />-----------------------------------------------------------------------------------------------------------------<br /><br />'; var_dump(curl_error($ch)); echo '<br /><br />-----------------------------------------------------------------------------------------------------------------<br /><br />'; echo $url; echo '<br /><br />-----------------------------------------------------------------------------------------------------------------<br /><br />'; // close funnel curl_close($ch); $headers = 'mime-version: 1.0' . "\r\n"; $headers .= 'content-type: text/html; charset=iso-8859-1' . "\r\n"; // mail mail('***@gmail.com', 'predracun', $response, $headers); ?>
this have , it's throwing me 500 error when run script.
Comments
Post a Comment