查看他的登陸頁面的代碼, 看他提交到哪個頁面, 變量是什麼。
復制代碼 代碼如下:
<form method="post" action="login.jsp">
<table align="center" width="40%" border="0" cellpadding="0" cellspacing="2">
<tr>
<td width="30%" align="right" bgcolor="#0073AA" >name:</td>
<td width="70%"><input type="text" size="30" name="username"></td>
</tr>
<tr>
<td width="30%" align="right" bgcolor="#0073AA" >password:</td>
<td width="70%"><input type="password" size="32" name="passwd"></td>
</tr>
<tr>
<td colspan="2" align="right">
<input type="submit" name="submit" value="Login">
<input type="button" name="submit" value="regest" onclick="location.href='regest.jsp'">
</td>
</tr>
</table>
</form>
很明顯, 如果你要登陸, 你需要把username, passwd, submit這幾個變量post到login.jsp, 而且submit=Login
用以下代碼:
復制代碼 代碼如下:
<?php
$postData = "username=your_name&password=your_password&Submit=Login";
$posturl = "http://......../../login.jsp";
$postUrl = parse_url($posturl);
$host = $postUrl[host] ? $postUrl[host] : "";
$port = $postUrl[port] ? $postUrl[port] : 80;
$path = $postUrl[path] ? $postUrl[path] : "/";
$fsp = fsockopen($host, $port, &$errno, &$errstr, 30);
if(!$fsp){
print "\nopen socket failed\n";
}else{
fwrite($fsp, "POST ".$path." HTTP/1.1\r\n");
fwrite($fsp, "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*\r\n");
fwrite($fsp, "Accept-Language: zh-cn\r\n");
fwrite($fsp, "Content-Type: application/x-www-form-urlencoded\r\n");
fwrite($fsp, "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon)\r\n");
fwrite($fsp, "Host:".$host."\r\n");
fwrite($fsp, "Content-Length: ".strlen($postData)."\r\n\r\n");
fwrite($fsp, $postData);
$resp = "";
do{
if(strlen($out=fread($fsp, 1024)) == 0) break;
$resp .= $out;
}while(true);
echo "<br><br>".nl2br($resp);
fclose($fsp);
}
?>