zoukankan      html  css  js  c++  java
  • PHP curl登录 跳过验证码

    <?php
    switch($_GET['do']){
        case 'vc':
            $cookieFile = "./test.tmp";
            $url = 'http://localhost/test/login.php?do=vcode&?r='.rand();
            $ch = curl_init($url);
            curl_setopt($ch,CURLOPT_COOKIEJAR, $cookieFile); // 把返回来的cookie信息保存在文件中
            curl_exec($ch);
            curl_close($ch);
            exit;
            break;
        case 'login':
            $pars = http_build_query($_GET);
            $cookieFile = "./test.tmp";
            $url = 'http://localhost/test/login.php?do=login&'.$pars;
            $ch = curl_init($url);
            curl_setopt($ch,CURLOPT_COOKIEFILE, $cookieFile); //同时发送Cookie
            curl_exec($ch);
            curl_close($ch);
            //虚拟操作
            $url = 'http://localhost/test/login.php?do=dosth';
            $ch = curl_init($url);
            curl_setopt($ch,CURLOPT_COOKIEFILE, $cookieFile); //同时发送Cookie
            curl_exec($ch);
            curl_close($ch);
            exit;
            break;
        default :
            break;
    }
    ?>
    <html>
        <form action="">
            <input type="hidden" value="login" name="do">
            <input type="text" value="test" name="u">
            <input type="password" value="testp" name="p">
            <input type="text" value="" name="vc">
            <input type="submit" value="OK"> 
            <iframe src="http://localhost/test/vmlogin.php?do=vc" ><iframe>
        </form>
    </html>

    登录页面 login.php:

    <?php
    session_start();
    switch($_GET['do']){
        case 'vcode':
            echo $_SESSION['vc'] = rand(100,999);
            exit();
            break;
        case 'login':
            if($_GET['vc'] !=  $_SESSION['vc'])
                die('veryfy code error');
            $auth = array('test'=>'testp');    
            if($auth[$_GET['u']] == $_GET['p']){
                $_SESSION['has_login'] = 1;
                header("location:http://localhost/test/");
            }else{
                die('invalid user/pwd');
            }
            exit();
            break;
        case 'dosth':
            if($_SESSION['has_login'])
                exit("do sth");
            else
                exit("no privilege");
            break;
        default: 
            break;
    }
    ?>
    <html>
        <form action="">
            <input type="text" value="" name="u">
            <input type="password" value=""  name="p">
            <input type="text" value="" name="vc">
            <input type="hidden" value="login" name="do">
            <input type="submit" value="OK"> 
            <iframe src="http://localhost/test/login.php?do=vcode" ><iframe>
        </form>
    </html>
  • 相关阅读:
    静态类和静态类成员(C# 编程指南)
    sealed(C# 参考)
    C#高级知识点概要(2)
    线程并发和异步
    CXF+Spring+Hibernate实现RESTful webservice服务端实例
    Spring Boot 实现RESTful webservice服务端实例
    Spring Boot 实现RESTful webservice服务端示例
    Spring Boot REST API 自动化测试
    Biee插入图形时报错-超过了已配置的已允许输出提示, 区域, 行或列的最大数目
    BIEE安装一直卡在最后一步解决办法
  • 原文地址:https://www.cnblogs.com/glory-jzx/p/3596702.html
Copyright © 2011-2022 走看看