查询系统
前几天做了个大学英语四六级成绩查询系统,一个 phprpc 版本,一个 wap 版本。它们的核心代码都是相同的。下面就是从 etang.cet 获取大学英语四六级成绩的核心代码:
下载: cetquery.php
function query($examid, $examtype) { $examid = trim($examid); $examtype = trim($examtype); if (!is_numeric($examid)) { return '准考证号码必须是数字'; } if (strlen($examid) != 15) { return '准考证号码不正确'; } if ($examtype == '1') { if ((substr($examid, 6, 4) != '0521') && (substr($examid, 6, 4) != '1052')) { return '准考证号码与考试类型不符'; } } if ($examtype == '2') { if ((substr($examid, 6, 4) != '0512') && (substr($examid, 6, 4) != '0522') && (substr($examid, 6, 4) != '2052')) { return '准考证号码与考试类型不符'; } } $examid1 = substr($examid, 0, 6) . $examtype . '052' . substr($examid, 10, 5); $request = examtype=$examtype&examid=$examid&image.x=23&image.y=32; $content_len = strlen($request); $handle = @fsockopen('cet.etang.com', 80, $errno, $errstr, 10); $buf = ''; $id = base_convert(mt_rand().mt_rand(), 10, 36); if ($handle) { $http_request = post /dog/cet http/1.0\r\n . accept: */*\r\n . referer: http://cet.etang.com/cet_girldemand_$id.htm\r\n . user-agent: mozilla/4.0 (compatible; msie 6.0; windows nt 5.1; sv1; alexa toolbar)\r\n . host: cet.etang.com\r\n . content-type: application/x-www-form-urlencoded\r\n . content-length: $content_len\r\n . cache-control: no-cache\r\n . cookie: zi=a; examid1=$examid; examtype1=$examtype; sex=girl; examid=$examid1; examtype=$examtype\r\n . \r\n . $request; fputs($handle, $http_request, strlen($http_request)); while (!feof($handle)) { $buf .= fgets($handle, 128); } fclose($handle); } else { return 查询服务器暂时无法连接; } $buf = explode(\r\n, $buf); $buf = $buf[11]; $score = ; if (substr($buf, 0, 18) == 'set-cookie: score=') { $score = substr($buf, 18, strpos($buf, ';') - 18); } if (($score != '') and ($score != 'error')) { $score = explode(',', $score); } else { return '你所查询的准考证号码不存在'; } return $score; }