您好,登錄后才能下訂單哦!
這期內容當中小編將會給大家帶來有關利用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=$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); //通過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>
一、phpStudy,是一個新手入門最常用的開發環境。二、WampServer,WampServer也同樣的也是和phpStudy一樣操作簡單對小白比較友好。三、XAMPP,XAMPP(Apache+MySQL+PHP+PERL)是一個功能強大的建站集成軟件包;四、MAMP,MAMP分為兩種MAMP和MAMP Pro for Mac。五、寶塔面板,寶塔面板是一款服務器管理軟件,支持windows和linux系統。六、UPUPW,UPUPW是目前Windows平臺下最具特色的Web服務器PHP套件。
上述就是小編為大家分享的利用PHP怎么 模擬登陸功能了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關知識,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。