您的位置:首页 > 理论基础 > 计算机网络

PHP HttpClient模拟登陆

2015-02-11 21:40 357 查看
这里面的参数,$xuehao,$mm,$zym就是验证码,学号,密码,$lt是登陆页面的隐藏信息。我们可以通过发fiddler查看

比如工大的模拟登陆:

也可以通过查看源代码 搜索<input

就会发现lt这个属性,然后我们如何获取其值呢?。。我们可以现在模拟登陆的界面获取,代码如下:

<?php
header("content-Type: text/html; charset=utf-8");
include_once("./httpClient.php");
$client = new httpClient("cas.nwpu.edu.cn");
$client->get("/cas");
$html = $client->getContent();
$header = $client->getHeaders();
print_r($header);
$nesoft = $header['set-cookie'];//neusoftnwpudcp=hTCsJbhWpmG5TVTzLcnsTNJVpjQrgwByvJyL42srRGvRZZH2Ldbr!1675837507
$nesoft = substr($nesoft, 15, 63);
$cookie = Array("neusoftnwpudcp"=>$nesoft);
$client->setCookies($cookie,true);

$client->get("/cas/Captcha.jpg");
$img = $client->getContent();
$file = fopen("Captcha.jpg", "w");
fwrite($file, $img);
fclose($file);
//$preg="/name=\"lt\" value=\"LT_nwpuapp[\d]+_-[\d]+-[\w]*/";
$preg = "/name=\"lt\" value=\"LT_nwpuapp[\d]+_-[\d]+-[\w]*/";
preg_match($preg, $html, $hidden);
$hidden = $hidden[0];
print_r($hidden);
//$preg="/LT_nwpuapp[\d]+_-[\d]+-[\w]+/";
$preg = "/LT_nwpuapp[\d]+_-[\d]+-[\w]+/";
preg_match($preg, $hidden, $hidden_value);
$hidden_value = $hidden_value[0];

?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form method="post" action="index1.php">
账号:<input type="text" value="2013303461" name="xuehao" /><br/>
密码:<input type="password" value="043017" name="mm" /><br/>
验证码:<input type="text" value="" name="yzm" /><img src="Captcha.jpg"/><br/>
<input type="Submit" value="查询"/>
<input type="hidden" name="neusoftnwpudcp" value="<?php echo $nesoft;?>"/>
<input type="hidden" name="hidden_value" value="<?php echo $hidden_value;?>" />
</form>
</body>
</html>

上式是通过正则表达式,来描述的
模拟登陆有两种方法,HTTPClient和CURL两种方法,以上是HTTPClient,,,两种方法都不太熟,以后再多多练习吧
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息