I have a problem with PHP cURL login form. Ihave successefuly logged id the site and wrote my cookie in the file, than I visit the page again with the same cookie and it doesn't work... Please help!
My code for login is this:
$linkP = "https://www.something.com/login.php";
$postData = array(
'user' => 'something',
'pass' => 'something'
);
$userAgent = 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36';
$header = true;
$cookie = $_SERVER['DOCUMENT_ROOT'].'/tmp/cookie';
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, $header);
curl_setopt($ch, CURLOPT_URL, $linkP);
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
$result = curl_exec($ch);
curl_close($ch);
My cookie file contents are this:
# Netscape HTTP Cookie File
# http://curl.haxx.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.
.something.com TRUE / FALSE 0 stas 985mupc786rg6crikotnfj3oj3
My code for visting again is:
$cookie=$_SERVER['DOCUMENT_ROOT'].'/tmp/cookie';
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $link);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.17 Safari/537.36");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie);
$html = curl_exec($ch);
echo $html;
It doesn't stay logged id. The other interesting thing is that if I login with browser manually and i take the hash from cookie and replace it with my generated cookie, than it works just fine. I don't see the point. Where is the difference?