PHP 模擬登陸功能實(shí)例詳解
本文實(shí)例講述了PHP 模擬登陸功能。分享給大家供大家參考,具體如下:
說(shuō)明:該模擬登陸實(shí)例僅適用于沒(méi)有驗(yàn)證碼的模擬登陸實(shí)例
該程序基本功能是,模擬登陸高校圖書(shū)館網(wǎng)站,并獲取讀者信息和借書(shū)信息。
程序截圖:
目錄結(jié)構(gòu):
login.php
<form method="post" class="am-form" action="judge.php"> <label for="sid">學(xué)號(hào):</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=$number&passwd=$passwd&select=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); //通過(guò)curl抓取數(shù)據(jù) $pattern = '/<td class="whitetext" width="35%"><a class="blue" href="(.*)" rel="external nofollow" >(.*)<\/a>/';//正則匹配獲得圖書(shū)信息 preg_match_all($pattern, $res,$book_arr); $booklist = array(); $booklist = $book_arr[2]; //借閱圖書(shū)列表 //var_dump($booklist); $pattern = '/<font color=(red|)>(.*)<\/font>/';//正則匹配獲得還書(shū)信息 preg_match_all($pattern, $res,$date_arr); $datelist = array(); $datelist = $date_arr[2]; //應(yīng)歸還日期列表 $taglist = array(); $taglist = $date_arr[1]; //標(biāo)記是否超期 //var_dump($date_arr); ?>
logout.php
<?php session_start(); $_SESSION = array(); session_destroy(); ?> <script>window.location.href='login.php'</script>
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php curl用法總結(jié)》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《PHP數(shù)據(jù)結(jié)構(gòu)與算法教程》及《PHP中json格式數(shù)據(jù)操作技巧匯總》
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。
- php實(shí)現(xiàn)模擬登陸方正教務(wù)系統(tǒng)抓取課表
- PHP函數(shù)分享之curl方式取得數(shù)據(jù)、模擬登陸、POST數(shù)據(jù)
- PHP實(shí)現(xiàn)微信模擬登陸并給用戶發(fā)送消息的方法【文字,圖片,圖文】
- php模擬登陸的實(shí)現(xiàn)方法分析
- php中通過(guò)curl模擬登陸discuz論壇的實(shí)現(xiàn)代碼
- php 論壇采集程序 模擬登陸,抓取頁(yè)面 實(shí)現(xiàn)代碼
- PHP簡(jiǎn)單實(shí)現(xiàn)模擬登陸功能示例
- php實(shí)現(xiàn)微信模擬登陸、獲取用戶列表及群發(fā)消息功能示例
- PHP 模擬登陸MSN并獲得用戶信息
- php通過(guò)curl模擬登陸DZ論壇
- PHP模擬登陸163郵箱發(fā)郵件及獲取通訊錄列表的方法
相關(guān)文章
PHP編程獲取各個(gè)時(shí)間段具體時(shí)間的方法
這篇文章主要介紹了PHP編程獲取各個(gè)時(shí)間段具體時(shí)間的方法,結(jié)合實(shí)例形式分析了基于date與strtotime函數(shù)進(jìn)行日期時(shí)間運(yùn)算的相關(guān)操作技巧,需要的朋友可以參考下2017-05-05PHP圖片處理之圖片旋轉(zhuǎn)和圖片翻轉(zhuǎn)實(shí)例
這篇文章主要介紹了PHP圖片處理之圖片旋轉(zhuǎn)和圖片翻轉(zhuǎn)實(shí)例,本文使用imagerotate函數(shù)實(shí)現(xiàn),自定義了多個(gè)函數(shù)來(lái)實(shí)現(xiàn)功能需求,需要的朋友可以參考下2014-11-11晉城吧對(duì)DiscuzX進(jìn)行的前端優(yōu)化要點(diǎn)
晉城吧的服務(wù)器在美國(guó),延遲相對(duì)國(guó)內(nèi)略微要高一些,所以優(yōu)化就顯得非常重要。2010-09-09php echo, print, print_r, sprintf, var_dump, var_expor的使用區(qū)別
本篇文章是對(duì)php中echo, print, print_r, sprintf, var_dump, var_expor的使用區(qū)別進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06PHP 創(chuàng)建標(biāo)簽云函數(shù)代碼
PHP創(chuàng)建標(biāo)簽云函數(shù)代碼,使用此函數(shù)創(chuàng)建標(biāo)簽云。2010-05-05Session服務(wù)器配置指南與使用經(jīng)驗(yàn)的深入解析
本篇文章是對(duì)Session服務(wù)器配置指南與使用經(jīng)驗(yàn)進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06