• 模拟登录学校教务管理系统,获取成绩单!


    界面如下:

    这个模拟是高仿真学校教务系统的,好处就是,可以快速登陆系统直接获取成绩。

    避开了繁琐的查询步骤,和节约了查询的时间,极大的提高了用户的体验。

    核心源代码如下:

     <?php
    
        //屏蔽notice信息
        error_reporting(E_ALL ^ E_NOTICE);  
    
        //设置文本头信息
        header("Content-Type:text/html;charset=utf-8");
    
        if ( $_REQUEST['xh'] && $_REQUEST['psw']){    
            $get= new Index();
            $flag = $get->login();
            if ( false == $flag) exit('学号或密码错误!');
            echo $get->getResults();
        }
    
    
    class Index{
    
        private $_cookie;
    
        //验证登录操作
        public function login(){
    
            $url = 'http://202.197.224.134:8083/jwgl/logincheck.jsp';
    
            $post = 'identity=student&username='.$_REQUEST['xh'].'&password='.$_REQUEST['psw'];
    
            $stream = $this->_html($url, $post);
    
            //将$strean由gbk编码转换为utf-8编码
            $stream = mb_convert_encoding($stream, 'utf-8', 'gbk');
    
            $this->_cookie($stream); // 获取cookie
            
            $url = 'http://202.197.224.134:8083/jwgl/index1.jsp';
    
            $html = $this->_html($url, $post.'&role=1');
            
            return strpos($stream, '页面跳转') !== false;
        }
    
        //查询成绩的方法
        public function getResults(){
    
            $url= 'http://202.197.224.134:8083/jwgl/cj/cj1_cjLiebiao.jsp?xq=null&xkjc='.$_REQUEST['xkjc'].'&type=null&xkdl2=1&xh='.$_REQUEST['xh'].'&bh=null';
    
    
            $stream = $this->_html($url);
    
            $stream = mb_convert_encoding($stream, 'utf-8', 'gbk');
    
    
            //搜索 $stream中所有匹配 '/<td>(.*?)</td>/is' 给定正则表达式 的匹配结果并且将它们以 flag 指定顺序输出到 $match 中. 
            preg_match_all('/<td>(.*?)</td>/is', $stream, $match);
    
             $len=count($match[1],1);
    
    
            echo "<table  align='center' width='80%' border='1' cellspacing='0'  bordercolor='#3399cc'  cellpadding='2'><tr style='color:#000000;font-size:15px' bgcolor='#3399cc'><td  colspan='8' align='center'>湘潭大学学号为<<<font color='red' style='font-weight:bold;'>".$_REQUEST['xh']."</font>>>的成绩单</td>";
            $j=0;
            for($i=1;$i<=($len+1)/7;$i++){
                
                echo "<tr>";
                for(;$j<=$len;$j++){    
                    echo "<td>".$match[1][$j]."</td>";
                    if(($j+1)%7==0){
                        $j=$j+1;
                        break;
                    }
                }
                echo "</tr>";
            }
            echo "</table>";
        }
        
        private function _cookie($stream){
        
            preg_match_all("/Set-Cookie: (.*?);/is", $stream, $matches);        
            $this->_cookie = @implode(";", $matches[1]);
        }
        
        private function _html($url, $post = FALSE){
        
            ob_start();
    
            //初始化curl模块
            $ch = curl_init($url); 
    
            //是否显示头信息
            curl_setopt($ch, CURLOPT_HEADER, true);
    
            //设置cURL允许执行的最长秒数
            curl_setopt($ch, CURLOPT_TIMEOUT, 60);
    
            if ( $post){
    
                //post方式提交
                curl_setopt($ch, CURLOPT_POST, true);
    
                //要提交的信息
                  curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
            }
    
            //设置cookie信息,保存在指定的文件中
            curl_setopt($ch, CURLOPT_COOKIE, $this->_cookie);
    
            //执行curl
            curl_exec($ch);  //执行cURL抓取页面内容 
    
            //关闭cURL资源,并且释放系统资源 
            curl_close($ch);
    
            //此函数返回输出缓冲区的内容
            $_str = ob_get_contents();
    
            //去除所有输出缓冲区
            ob_end_clean();
    
            return $_str;
        }
    }
    
        echo "<a href='a.html' style='margin-left:45%;'><input type='button' value='返回查成绩首页'></a>";
    ?>
  • 相关阅读:
    ajax封装
    完美运动框架
    表单上传input=file
    面向对象入门
    浅谈javaScript内存
    关于使用iframe的父子页面进行简单的相互传值
    浅谈原生JavaScript的动画和特效
    rem 原理与简介
    移动 web 适配
    jsonp 简单封装
  • 原文地址:https://www.cnblogs.com/yxhblogs/p/4749184.html
Copyright © 2020-2023  润新知