Home  >  Article  >  Backend Development  >  How to use a script to imitate the login process_PHP tutorial

How to use a script to imitate the login process_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 16:00:37764browse

Look at the code of his login page to see which page he submitted to and what the variables are.

Copy code The code is as follows:





< td width="70%">


       
 < td width="70%">




name:
password:






Obviously, if you want to log in, you need to post the username, passwd, and submit variables to login.jsp, and submit=Login
Use the following code:
Copy the code The code is as follows:

        $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 "

".nl2br($resp);

                fclose($fsp);

        }
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/317083.htmlTechArticle查看他的登陆页面的代码,看他提交到哪个页面,变量是什么。 复制代码 代码如下: formmethod="post"action="login.jsp" tablealign="center"width="40%"sty...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn