当前位置:首页 > PHP教程 > PHP高级教程

如何使用脚本模仿登陆过程

查看他的登陆页面的代码, 看他提交到哪个页面, 变量是什么。
复制代码 代码如下:

<form method="post" action="login.jsp">
<table align="center" width="40%" style="font-size: 12px" border="0" cellpadding="0" cellspacing="2">
  <tr>
    <td width="30%" align="right" bgcolor="#0073aa" style="font-size: 12px;color:#ffffff">name:</td>
    <td width="70%"><input type="text" size="30" name="username"></td>
  </tr>
  <tr>
    <td width="30%" align="right" bgcolor="#0073aa" style="font-size: 12px;color:#ffffff">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 failedn";
        }else{
                fwrite($fsp, "post ".$path." http/1.1rn");
                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, */*rn");
                fwrite($fsp, "accept-language: zh-cnrn");
                fwrite($fsp, "content-type: application/x-www-form-urlencodedrn");
                fwrite($fsp, "user-agent: mozilla/4.0 (compatible; msie 6.0; windows nt 5.1; sv1; maxthon)rn");
                fwrite($fsp, "host:".$host."rn");
                fwrite($fsp, "content-length: ".strlen($postdata)."rnrn");
                fwrite($fsp, $postdata);

                $resp = "";
                do{
                        if(strlen($out=fread($fsp, 1024)) == 0) break;
                        $resp .= $out;
                }while(true);

                echo "<br><br>".nl2br($resp);

                fclose($fsp);

        }
?>


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!