0
我想自動登錄到網站並重定向。我正在做這個使用curl這裏是我的代碼,但它不適合我我的意思是它沒有做自動登錄,即使我的登錄細節是正確的我可以直接登錄,但不能通過捲曲php。 這裏是我的代碼:PHP自動登錄和使用curl重定向
function login($url,$data){
$fp = fopen("cookie.txt","w");
fclose($fp);
$login = curl_init();
curl_setopt($login,CURLOPT_COOKIEJAR,"cookie.txt");
curl_setopt($login,CURLOPT_COOKIEFILE,"cookie.txt");
curl_setopt($login,CURLOPT_TIMEOUT, 40000);
curl_setopt($login,CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($login,CURLOPT_URL,$url);
curl_setopt($login,CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
curl_setopt($login,CURLOPT_FOLLOWLOCATION,TRUE);
curl_setopt($login,CURLOPT_POST,TRUE);
curl_setopt($login,CURLOPT_POSTFIELDS,$data);
ob_start();
return curl_exec($login);
ob_end_clean();
curl_close($login);
unset($login);
}
function grab_page($site){
$ch= curl_init();
curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
curl_setopt($ch,CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch,CURLOPT_TIMEOUT,40);
curl_setopt($ch,CURLOPT_COOKIEFILE,"cookie.txt");
curl_setopt($ch,CURLOPT_URL,$site);
ob_start();
return curl_exec($ch);
ob_end_clean();
curl_close($ch);
unset($ch);
}
function post_data($site,$data){
$datapost = curl_init();
$headers=array("Expect:");
curl_setopt($datapost,CURLOPT_URL,$site);
curl_setopt($datapost,CURLOPT_TIMEOUT,40000);
curl_setopt($datapost,CURLOPT_HEADER,TRUE);
curl_setopt($datapost,CURLOPT_HTTPHEADER,$headers);
curl_setopt($datapost,CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
curl_setopt($datapost,CURLOPT_POST,TRUE);
curl_setopt($datapost,CURLOPT_POSTFIELDS,$data);
curl_setopt($ch,CURLOPT_COOKIEFILE,"cookie.txt");
ob_start();
return curl_exec($datapost);
ob_end_clean();
curl_close($datapost);
unset($datapost);
}
echo login("https://www.jollywallet.com/api/aff","token=00D3A9E8-A9F4-F21B-122E-54AF4B00A0E8&captcha%5Binput%5D=&captcha%5Bid%5D=&type=login&[email protected]&dist_id=0&dist_sub_id=0&password=4704e86d0ea8a20752a9b882b9a2a5f9®_option=2");
echo grab_page("https://www.jollywallet.com/jollywallet/storelist");