• 企业400电话
  • 微网小程序
  • AI电话机器人
  • 电商代运营
  • 全 部 栏 目

    企业400电话 网络优化推广 AI电话机器人 呼叫中心 网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    PHP 模拟登陆功能实例详解

    本文实例讲述了PHP 模拟登陆功能。分享给大家供大家参考,具体如下:

    说明:该模拟登陆实例仅适用于没有验证码的模拟登陆实例

    该程序基本功能是,模拟登陆高校图书馆网站,并获取读者信息和借书信息。

    程序截图:

    目录结构:

    login.php

    form method="post" class="am-form" action="judge.php">
       label for="sid">学号:/label>
       input type="text" name="number" id="sid" value="">
       br>
       label for="password">密码:/label>
       input type="password" name="passwd" id="password" value="">
       br>
       div class="am-cf">
        input type="submit" name="" value="登 录" class="am-btn am-btn-primary am-btn-sm am-fl">
        input type="submit" name="" value="忘记密码 ^_^? " class="am-btn am-btn-default am-btn-sm am-fr">
       /div>
      /form>
    
    

    judge.php

    session_start();
    require_once 'curl.php';
    $url = "http://opac.lib.ustc.edu.cn/reader/redr_info.php";
    $number = $_POST['number'];
    $passwd = $_POST['passwd'];
    $res = run_curl($url,$number,$passwd);
    $pattern = '/TD>span class=\"bluetext\">姓名:\/span>(.*)\/TD>/';
    preg_match($pattern, $res,$arr1);
    if(is_array($arr1)){
     $_SESSION['number'] = $number;
     $_SESSION['passwd'] = $passwd;
     $_SESSION['name'] = $arr1[1];
     echo "script>window.location.href='index.php';/script>";
    }else{
     echo "script>history.go(-1);/script>";
    }
    
    

    curl.php

    ?php
    function run_curl($content_url,$number='',$passwd=''){
      $cookie_file = tempnam('./temp','cookie');
      $url = "http://opac.lib.ustc.edu.cn/reader/redr_verify.php";
      $ch = curl_init($url);
      curl_setopt($ch, CURLOPT_HEADER, 0);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
      $post_fileds = "number=$numberpasswd=$passwdselect=bar_no";
      curl_setopt($ch,CURLOPT_POST,1);
      curl_setopt($ch,CURLOPT_POSTFIELDS,$post_fileds);
      curl_setopt($ch,CURLOPT_COOKIEFILE,$cookie_file);
      curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie_file);
      $content = curl_exec($ch);
      curl_close($ch);
      $ch = curl_init($content_url);
      curl_setopt($ch, CURLOPT_HEADER, 0);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
      curl_setopt($ch,CURLOPT_COOKIEFILE,$cookie_file);
      curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie_file);
      $res = curl_exec($ch);
      curl_close($ch);
      return $res;
    }
    
    

    index.php

    ?php
      session_start();
      $number = $_SESSION['number'];
      $passwd = $_SESSION['passwd'];
      $username = $_SESSION['name'];
      if($number==''||$passwd==''||$username==''){
        echo "script>window.location.href='login.php';/script>";
        exit();
      }
      require_once 'curl.php';
      header('Content-type:text/html;charset=utf-8');
      $url = "http://opac.lib.ustc.edu.cn/reader/book_lst.php";
      $res = run_curl($url,$number,$passwd); //通过curl抓取数据
      $pattern = '/td class="whitetext" width="35%">a class="blue" href="(.*)" rel="external nofollow" >(.*)\/a>/';//正则匹配获得图书信息
      preg_match_all($pattern, $res,$book_arr);
      $booklist = array();
      $booklist = $book_arr[2];  //借阅图书列表
      //var_dump($booklist);
      $pattern = '/font color=(red|)>(.*)\/font>/';//正则匹配获得还书信息
      preg_match_all($pattern, $res,$date_arr);
      $datelist = array();
      $datelist = $date_arr[2];  //应归还日期列表
      $taglist = array();
      $taglist = $date_arr[1];  //标记是否超期
      //var_dump($date_arr);
    ?>
    
    

    logout.php

    ?php
    session_start();
    $_SESSION = array();
    session_destroy();
    ?>
    script>window.location.href='login.php'/script>
    
    

    更多关于PHP相关内容感兴趣的读者可查看本站专题:《php curl用法总结》、《PHP网络编程技巧总结》、《PHP数组(Array)操作技巧大全》、《php字符串(string)用法总结》、《PHP数据结构与算法教程》及《PHP中json格式数据操作技巧汇总》

    希望本文所述对大家PHP程序设计有所帮助。

    您可能感兴趣的文章:
    • php实现模拟登陆方正教务系统抓取课表
    • PHP函数分享之curl方式取得数据、模拟登陆、POST数据
    • PHP实现微信模拟登陆并给用户发送消息的方法【文字,图片,图文】
    • php模拟登陆的实现方法分析
    • php中通过curl模拟登陆discuz论坛的实现代码
    • php 论坛采集程序 模拟登陆,抓取页面 实现代码
    • PHP简单实现模拟登陆功能示例
    • php实现微信模拟登陆、获取用户列表及群发消息功能示例
    • PHP 模拟登陆MSN并获得用户信息
    • php通过curl模拟登陆DZ论坛
    • PHP模拟登陆163邮箱发邮件及获取通讯录列表的方法
    上一篇:Yii框架日志操作图文与实例详解
    下一篇:mysqli扩展无法在PHP7下升级问题的解决
  • 相关文章
  • 

    © 2016-2020 巨人网络通讯

    时间:9:00-21:00 (节假日不休)

    地址:江苏信息产业基地11号楼四层

    《增值电信业务经营许可证》 苏B2-20120278

    PHP 模拟登陆功能实例详解 PHP,模拟,登陆,功能,实例,