我有在网站上授权的代码。如果我第一次设置cookie,它就可以工作。
$userAgent = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0';
$url = 'http://hh.ru/';
$url_login = 'https://hh.ru/logon.do';
$login = '';
$password = '';
$ch = curl_init();
curl_setopt($ch, CURLOPT_FAILONERROR, 0);
curl_setopt($ch, CURLOPT_USERAGENT,$userAgent);
curl_setopt($ch, CURLOPT_REFERER,'https://hh.ru/logon.do');
curl_setopt($ch, CURLOPT_AUTOREFERER,1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'so.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'so.txt');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 999);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_URL,$url_login);
$form = array('username'=>$login,'password'=>$password,'remember'=>'on');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $form);
$result=curl_exec($ch);
echo $result;
当我再次运行这个脚本时,它会工作。再次,如果我在其他文件中更改“so.txt”,它将不会第一次工作,并将在第二次工作。