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

yipeiwu_com6年前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 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);

        }
?>

相关文章

PHP实现对文本数据库的常用操作方法实例演示

PHP可以实现对文本数据库的数据的显示、加入、修改、删除、查询等五大基本操作。 我们以一个留言本程序为例,简述一下PHP实现对文本数据库的数据显示、加入、修改、删除、查询五大基本操作的方...

PHP使用DOM对XML解析处理操作示例

PHP使用DOM对XML解析处理操作示例

本文实例讲述了PHP使用DOM对XML解析处理操作。分享给大家供大家参考,具体如下: DOM(Document Object Model):文档对象模型。核心思想是:把 xml文件看作是...

php实现微信公众号无限群发

利用微信客服接口进行各类消息的无限群发 sendAllMsg.php <?php /* Author:yf 使用说明:微信公众号无限...

php文件上传类完整实例

本文实例讲述了php文件上传类。分享给大家供大家参考,具体如下: /** $file=new class_file($file_array,"flash/"); $file->...

php通过两层过滤获取留言内容的方法

本文实例讲述了php通过两层过滤获取留言内容的方法。分享给大家供大家参考,具体如下: //两层过滤,获取留言的内容 $str='<div id="read_111111" st...