您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
这期内容当中小编将会给大家带来有关利用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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。