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

界面如下:

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

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

核心源代码如下:

复制代码
 <?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>";
?>
复制代码

 

posted @   Yxh_blogs  阅读(2351)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示