本文目錄一覽:
怎樣用php中的curl模擬登陸
在我的博客《PHP cURL模擬登錄與採集分析過程詳解》做了詳細的介紹,步驟有:
1. 訪問目標網站
2. 打開Firebug(快捷鍵:F12)
3. 清除【Cookie】
4. 重新訪問目標網站
5. 設置【網絡】為[保持]狀態
6. 填寫表單,提交登錄請求
7. 利用【網絡】,分析提交信息
8. 複製請求的cURL命令
9. 分析命令傳輸的參數與Cookie和前面頁面響應內容的關聯性
10. 如果遇到Cookie和響應內容都無法查找到的參數,Ctrl+S保存當前頁面為全部,利用文本搜索該參數的位置
11. 利用cURL命令組裝模擬登錄程序
詳情請參考博客內容:
PHP模擬用戶登錄模塊
html(login.html)
!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “”
html xmlns=””
head
meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″ /
title用戶登錄頁面/title
script language=”javascript”
function check(){
var user = document.getElementById(“user”);
var passwd = document.getElementById(“passwd”);
if(user.value.length == 0){
alert(“用戶名不能為空!”);
return false;
}
if(passwd.value.length 6){
alert(“密碼至少6位!”);
return false;
}
}
/script
/head
body
div style=” width:300px; height:200px; margin:auto auto;”
form name=”login” method=”post” action=”check_login.php”
table width=”300″ height=”200″ cellpadding=”0″ cellspacing=”0″ border=”1px”
tr
td height=”70″用戶名:/td
tdinput id=”user” name=”username” type=”text” //td
/tr
tr
td height=”78″密碼/td
tdinput id=”passwd” name=”password” type=”password” //td
/tr
tr
td colspan=”2″centerinput type=”submit” value=”登錄” onclick=”return check();” /input type=”reset” value=”重置” //center/td
/tr
/table
/form
/div
/body
/html
php(check_login.php)
?php
/*
* 驗證登錄頁
* 2015-6-6
* 預設用戶名admin,密碼1234567,
* 如果相同則顯示登錄成功!,錯誤則顯示用戶或密碼錯誤;
*/
$username = $_POST[‘username’];
$password = $_POST[‘password’];
if($username == ‘admin’ $password ==’1234567′){
echo “登錄成功!”;
}else{
echo “用戶或密碼錯誤”;
}
?
如何通過php程序模擬用戶登錄
模擬用戶可以用php的curl的post,例如
$url = “”;
$post_data = array (“username” = “uzuzuz”,”password” = “12345”);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// post數據
curl_setopt($ch, CURLOPT_POST, 1);
// post的變量
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$output = curl_exec($ch);
curl_close($ch);
//打印獲得的數據
print_r($output);
具體參考:
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/151400.html