-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.php
More file actions
76 lines (59 loc) · 2.34 KB
/
model.php
File metadata and controls
76 lines (59 loc) · 2.34 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
class fetch_html {
private $url, $cookie_jar;
public function __construct($_url, $_cookie = "cookie.txt") {
$this -> cookie_jar = $_cookie;
$this -> url = $_url;
}
public function login($page, $userid, $passwd) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this -> url . $page);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POST, 1);
$request = "txtS_NO=".$userid."&txtPerno=".$passwd."&LEVEL=0";
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_COOKIEJAR, $this -> cookie_jar);
curl_setopt($ch, CURLOPT_COOKIEFILE, $this -> cookie_jar);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
$html = curl_exec($ch);
curl_close($ch);
//suc -> i_Stu.asp
//fail -> Stu.asp
preg_match("/Location:\s(.*?)\s/", $html, $location);
if($location[1] == "i_Stu.asp") {
return true;
} else if($location[1] == "Stu.asp") {
return false;
}
}
public function logout() {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this -> url. "Logout.asp");
curl_setopt($ch, CURLOPT_COOKIEJAR, $this -> cookie_jar);
curl_setopt($ch, CURLOPT_COOKIEFILE, $this -> cookie_jar);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
curl_close($ch);
}
public function get_info($page) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this -> url. $page);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $this -> cookie_jar);
curl_setopt($ch, CURLOPT_COOKIEFILE, $this -> cookie_jar);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$re = iconv("BIG5", "UTF-8", curl_exec($ch));
curl_close($ch);
return $re;
}
public function __destruct() {
unset($url);
unset($cookie_jar);
}
}
?>