I need to login to some page by cURL in php.
I have this script :
$cookie_file = 'cookies.txt';
$c = curl_init();
curl_setopt($c, CURLOPT_URL, 'http://www.xxx.pl/index.php?act=ws&sub=login');
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_POSTFIELDS, 'login=aaa&pass=bbb');
curl_setopt($c, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($c, CURLOPT_REFERER, 'http://www.xxx.pl/index.php');
//curl_setopt($c, CURLOPT_HEADER, 1);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, 0);
//curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_COOKIEFILE, dirname(__FILE__) . '/'.$cookie_file);
curl_setopt($c, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/'.$cookie_file);
curl_exec($c);
curl_close($c);
When i run it the script log me in (i see new date in databse inserting on login) but when I open a site http://www.xxx.pl/ i am not loged.
I think problem is about sessions. But i dont know how to resolve it.
Starting session with cURL and capturing cookie data doesn’t mean that session will be shared between your app and browser.
If you run script from same domain you need to:
After performing these steps browser will send cookies back to the server which initiated session.