Home >php教程 >php手册 >大学英语四六级成绩查询系统核心代码

大学英语四六级成绩查询系统核心代码

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-21 09:05:582537browse

查询系统

  • 前几天做了个大学英语四六级成绩查询系统,一个 phprpc 版本,一个 wap 版本。它们的核心代码都是相同的。下面就是从 etang.cet 获取大学英语四六级成绩的核心代码:

    下载: cetquery.php
    1. function query($examid, $examtype) {
    2.     $examid = trim($examid);
    3.     $examtype = trim($examtype);
    4.     if (!is_numeric($examid)) {
    5.         return '准考证号码必须是数字';
    6.     }
    7.     if (strlen($examid) != 15) {
    8.         return '准考证号码不正确';
    9.     }
    10.     if ($examtype == '1') {
    11.         if ((substr($examid, 6, 4) != '0521') &&
    12.             (substr($examid, 6, 4) != '1052')) {
    13.             return '准考证号码与考试类型不符';
    14.         }
    15.     }
    16.     if ($examtype == '2') {
    17.         if ((substr($examid, 6, 4) != '0512') &&
    18.             (substr($examid, 6, 4) != '0522') &&
    19.             (substr($examid, 6, 4) != '2052')) {
    20.             return '准考证号码与考试类型不符';
    21.         }
    22.     }
    23.     $examid1 = substr($examid, 0, 6) . $examtype . '052' . substr($examid, 10, 5);
    24.     $request = "examtype=$examtype&examid=$examid&image.x=23&image.y=32";
    25.     $content_len = strlen($request);
    26.     $handle = @fsockopen('cet.etang.com', 80, $errno, $errstr, 10);
    27.     $buf = '';
    28.     $id = base_convert(mt_rand().mt_rand(), 10, 36);
    29.     if ($handle) {
    30.         $http_request =
    31.             "POST /dog/cet HTTP/1.0\r\n" .
    32.             "Accept: */*\r\n" .
    33.             "Referer: http://cet.etang.com/cet_girldemand_$id.htm\r\n" .
    34.             "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Alexa Toolbar)\r\n" .
    35.             "Host: cet.etang.com\r\n" .
    36.             "Content-Type: application/x-www-form-urlencoded\r\n" .
    37.             "Content-Length: $content_len\r\n" .
    38.             "Cache-Control: no-cache\r\n" .
    39.             "Cookie: zi=A; examid1=$examid; examtype1=$examtype; sex=girl; examid=$examid1; examtype=$examtype\r\n" .
    40.             "\r\n" .
    41.             $request;
    42.         fputs($handle, $http_request, strlen($http_request));
    43.         while (!feof($handle)) {
    44.             $buf .= fgets($handle, 128);
    45.         }
    46.         fclose($handle);
    47.     }
    48.     else {
    49.         return "查询服务器暂时无法连接";
    50.     }
    51.     $buf = explode("\r\n", $buf);
    52.     $buf = $buf[11];
    53.     $score = "";
    54.     if (substr($buf, 0, 18) == 'Set-Cookie: score=') {
    55.         $score = substr($buf, 18, strpos($buf, ';') - 18);
    56.     }
    57.     if (($score != '') and ($score != 'error')) {
    58.         $score = explode(',', $score);
    59.     }
    60.     else {
    61.         return '你所查询的准考证号码不存在';
    62.     }
    63.     return $score;
    64. }


  • Statement:
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn