-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.php
More file actions
49 lines (42 loc) · 1.41 KB
/
api.php
File metadata and controls
49 lines (42 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
function httpPost($url,$params){
$postData = '';
//create name value pairs seperated by &
foreach($params as $k => $v){
$postData .= $k . '='.$v.'&';
}
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT ,3);
curl_setopt($ch,CURLOPT_TIMEOUT, 20);
$output=curl_exec($ch);
curl_close($ch);
return $output;
}
if( isset($_GET['sem']) and isset($_GET['sid']))
{
if( is_numeric($_GET['sem']) and is_numeric($_GET['sid']))
{
echo file_get_contents("https://www3.reg.cmu.ac.th/regist".$_GET['sem']."/public/result.php?id=".$_GET['sid']);
}else{
echo "ERROR";
}
}elseif ( isset($_GET['sem']) and isset($_GET['c']) and isset($_GET['lec']) and isset($_GET['lab']) ){
if ( is_numeric($_GET['sem']) and is_numeric($_GET['c']) and is_numeric($_GET['lec']) and is_numeric($_GET['lab']) )
{
$params = array(
"s_course1" =>$_GET['c'],
"s_lec1" => $_GET['lec'],
"s_lab1" => $_GET['lab'],
"op" => "bycourse"
);
echo httpPost("https://www3.reg.cmu.ac.th/regist".$_GET['sem']."/public/search.php?act=search", $params);
}else{
echo "ERROR";
}
}
?>