PHP實現模擬登入

2021-07-10 03:26:01 字數 1444 閱讀 9967

方法一:在php中使用exec()函式執行linux shell語句

$cmd = "curl -d \"".$logininfostring."\" -c $filename $url";//訪問登入介面將cookie儲存到檔案

exec($cmd, $res);

$result = json_decode($res[0], true);

if (!empty($result['auth_code'])) else

$content = file_get_contents($filename);//取出cookie資訊

unlink($filename);

$content = strstr($content, 'user');

preg_match("/(?<=\")[\|\d\:\=a-za-z]/", $content, $matches);

$user = $matches[0];//正則匹配出cookie:user

$cmd = "curl -l -b \"user=".$user.';auth_code='.$auth_code."\" -d \"".$postquery." $url";//請求需要登入後才能訪問的url,帶上cookie:user和auth_code

exec($cmd, $res);

$result = $res[0];

?>

方法二:利用php curl方法

"cookie:user=".$user//curl httpheader將cookie帶上

),

php使用curl實現模擬登入例項

function login post url,cookie,post function get content url,cookie post array username 使用者名稱 password 密碼 usecookie 0 action login submit 1,cookie coo...

PHP如何獲取Cookie並實現模擬登入

一 定義cookie儲存路徑 必須使用絕對路徑 cookie jar dirwww.cppcns.comname file pic.cookie 二 獲取cookie 將cookie存入檔案 url ch curl init curvwakjkvgnl setopt ch,curlopt url,u...

python實現模擬登入

python實現模擬登入 2012 08 02 10 20 42 我來說兩句 收藏 當你要模擬登入乙個 時,首先要搞清楚 的登入處理細節 發了什麼樣的資料,給誰發等.我是通過httpfox來抓取http資料報來分析該 的登入流程。同時,我們還要分析抓到的post包的資料結構和header,要根據提交...