Commit 63385829fe268a8ffc6929802df5161e22df428d
1 parent
12bc3d93d4
Exists in
master
stock ketika gagal
Showing 1 changed file with 1 additions and 1 deletions Inline Diff
KiselScrap.php
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | Class KiselScrap { | 3 | Class KiselScrap { |
4 | 4 | ||
5 | # Object properties | 5 | # Object properties |
6 | var $reqid = ''; | 6 | var $reqid = ''; |
7 | var $msisdn = ''; | 7 | var $msisdn = ''; |
8 | var $product = ''; | 8 | var $product = ''; |
9 | var $user_agent = ''; | 9 | var $user_agent = ''; |
10 | var $session_id = ''; | 10 | var $session_id = ''; |
11 | var $session_status = 1; | 11 | var $session_status = 1; |
12 | var $resp_str = ''; | 12 | var $resp_str = ''; |
13 | var $resp_target = ''; | 13 | var $resp_target = ''; |
14 | var $resp_xml = ''; | 14 | var $resp_xml = ''; |
15 | var $source_page = ''; | 15 | var $source_page = ''; |
16 | var $fp = ''; | 16 | var $fp = ''; |
17 | 17 | ||
18 | function setRandomUserAgent() | 18 | function setRandomUserAgent() |
19 | { | 19 | { |
20 | $userAgents=array( | 20 | $userAgents=array( |
21 | "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)", | 21 | "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)", |
22 | "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6", | 22 | "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6", |
23 | "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)", | 23 | "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)", |
24 | "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)", | 24 | "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)", |
25 | "Opera/9.20 (Windows NT 6.0; U; en)", | 25 | "Opera/9.20 (Windows NT 6.0; U; en)", |
26 | "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 8.50", | 26 | "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 8.50", |
27 | "Mozilla/4.0 (compatible; MSIE 6.0; MSIE 5.5; Windows NT 5.1) Opera 7.02 [en]", | 27 | "Mozilla/4.0 (compatible; MSIE 6.0; MSIE 5.5; Windows NT 5.1) Opera 7.02 [en]", |
28 | "Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; fr; rv:1.7) Gecko/20040624 Firefox/0.9", | 28 | "Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; fr; rv:1.7) Gecko/20040624 Firefox/0.9", |
29 | "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/48 (like Gecko) Safari/48" | 29 | "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/48 (like Gecko) Safari/48" |
30 | ); | 30 | ); |
31 | $random = rand(0,count($userAgents)-1); | 31 | $random = rand(0,count($userAgents)-1); |
32 | 32 | ||
33 | $this->user_agent = $userAgents[$random]; | 33 | $this->user_agent = $userAgents[$random]; |
34 | } | 34 | } |
35 | 35 | ||
36 | function setTrxParam($reqid, $msisdn, $product) { | 36 | function setTrxParam($reqid, $msisdn, $product) { |
37 | $this->reqid = $reqid; | 37 | $this->reqid = $reqid; |
38 | $this->msisdn = $msisdn; | 38 | $this->msisdn = $msisdn; |
39 | $this->product = $product; | 39 | $this->product = $product; |
40 | } | 40 | } |
41 | 41 | ||
42 | function getRandomUserAgent() { | 42 | function getRandomUserAgent() { |
43 | return $this->user_agent; | 43 | return $this->user_agent; |
44 | } | 44 | } |
45 | 45 | ||
46 | function get_page($url){ | 46 | function get_page($url){ |
47 | 47 | ||
48 | if (!function_exists('curl_init')){ | 48 | if (!function_exists('curl_init')){ |
49 | die('Sorry cURL is not installed!'); | 49 | die('Sorry cURL is not installed!'); |
50 | } | 50 | } |
51 | 51 | ||
52 | $ch = curl_init(); | 52 | $ch = curl_init(); |
53 | curl_setopt($ch, CURLOPT_URL, $url); | 53 | curl_setopt($ch, CURLOPT_URL, $url); |
54 | curl_setopt($ch, CURLOPT_REFERER, $url); | 54 | curl_setopt($ch, CURLOPT_REFERER, $url); |
55 | curl_setopt($ch, CURLOPT_USERAGENT, $this->getRandomUserAgent()); | 55 | curl_setopt($ch, CURLOPT_USERAGENT, $this->getRandomUserAgent()); |
56 | curl_setopt($ch, CURLOPT_HEADER, 1); | 56 | curl_setopt($ch, CURLOPT_HEADER, 1); |
57 | 57 | ||
58 | curl_setopt($ch, CURLOPT_COOKIE, 'JSESSIONID=' . $this->getSessionId()); | 58 | curl_setopt($ch, CURLOPT_COOKIE, 'JSESSIONID=' . $this->getSessionId()); |
59 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | 59 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
60 | session_write_close(); | 60 | session_write_close(); |
61 | $output = curl_exec($ch); | 61 | $output = curl_exec($ch); |
62 | 62 | ||
63 | $date = date("Y-m-d H:i:s"); | 63 | $date = date("Y-m-d H:i:s"); |
64 | if(!curl_errno($ch)) | 64 | if(!curl_errno($ch)) |
65 | { | 65 | { |
66 | $info = curl_getinfo($ch); | 66 | $info = curl_getinfo($ch); |
67 | $log = "[$date] Took " . $info['total_time'] . ' seconds to send a request to ' . $info['url']."\n"; | 67 | $log = "[$date] Took " . $info['total_time'] . ' seconds to send a request to ' . $info['url']."\n"; |
68 | } else { | 68 | } else { |
69 | $log = "[$date] error" . curl_errno($ch)."\n"; | 69 | $log = "[$date] error" . curl_errno($ch)."\n"; |
70 | } | 70 | } |
71 | 71 | ||
72 | $fd = fopen("scrapper_kisel.log", "a+"); | 72 | $fd = fopen("scrapper_kisel.log", "a+"); |
73 | fwrite($fd, $log); | 73 | fwrite($fd, $log); |
74 | fclose($fd); | 74 | fclose($fd); |
75 | 75 | ||
76 | curl_close($ch); | 76 | curl_close($ch); |
77 | 77 | ||
78 | if(preg_match("/HTTP\/1\.1 302 Found/i", $output)) { | 78 | if(preg_match("/HTTP\/1\.1 302 Found/i", $output)) { |
79 | $this->session_status = -1; | 79 | $this->session_status = -1; |
80 | } | 80 | } |
81 | return 1; | 81 | return 1; |
82 | } | 82 | } |
83 | 83 | ||
84 | /** | 84 | /** |
85 | * Determine if a variable is iterable. i.e. can be used to loop over. | 85 | * Determine if a variable is iterable. i.e. can be used to loop over. |
86 | * | 86 | * |
87 | * @return bool | 87 | * @return bool |
88 | */ | 88 | */ |
89 | function isIterable($var) | 89 | function isIterable($var) |
90 | { | 90 | { |
91 | return $var !== null | 91 | return $var !== null |
92 | && (is_array($var) | 92 | && (is_array($var) |
93 | || $var instanceof Traversable | 93 | || $var instanceof Traversable |
94 | || $var instanceof Iterator | 94 | || $var instanceof Iterator |
95 | || $var instanceof IteratorAggregate); | 95 | || $var instanceof IteratorAggregate); |
96 | } | 96 | } |
97 | 97 | ||
98 | function clearResponseStr() { | 98 | function clearResponseStr() { |
99 | $this->resp_str = ''; | 99 | $this->resp_str = ''; |
100 | } | 100 | } |
101 | 101 | ||
102 | function printResponseStr() { | 102 | function printResponseStr() { |
103 | print $this->resp_str."\n"; | 103 | print $this->resp_str."\n"; |
104 | } | 104 | } |
105 | 105 | ||
106 | function printResponseXML() { | 106 | function printResponseXML() { |
107 | print $this->resp_xml; | 107 | print $this->resp_xml; |
108 | } | 108 | } |
109 | 109 | ||
110 | function parseResponse($query,$type) { | 110 | function parseResponse($query,$type) { |
111 | $dom = new DOMDocument; | 111 | $dom = new DOMDocument; |
112 | libxml_use_internal_errors(true); | 112 | libxml_use_internal_errors(true); |
113 | #print $this->resp_str; | 113 | #print $this->resp_str; |
114 | if (!@$dom->loadHTML($this->resp_str)) | 114 | if (!@$dom->loadHTML($this->resp_str)) |
115 | { | 115 | { |
116 | $errors=""; | 116 | $errors=""; |
117 | foreach (libxml_get_errors() as $error) { | 117 | foreach (libxml_get_errors() as $error) { |
118 | $errors.=$error->message."\n"; | 118 | $errors.=$error->message."\n"; |
119 | } | 119 | } |
120 | libxml_clear_errors(); | 120 | libxml_clear_errors(); |
121 | print "libxml errors: $errors \n"; | 121 | print "libxml errors: $errors \n"; |
122 | return; | 122 | return; |
123 | } | 123 | } |
124 | 124 | ||
125 | $xpath = new DOMXPath($dom); | 125 | $xpath = new DOMXPath($dom); |
126 | $entries = $xpath->query($query); | 126 | $entries = $xpath->query($query); |
127 | 127 | ||
128 | if ($this->isIterable($entries)) | 128 | if ($this->isIterable($entries)) |
129 | { | 129 | { |
130 | $resp_value = ''; | 130 | $resp_value = ''; |
131 | foreach ($entries as $entry) { | 131 | foreach ($entries as $entry) { |
132 | if(ltrim(rtrim($entry->nodeValue)) != '' and !preg_match("/setTimeout/",$entry->nodeValue)) { | 132 | if(ltrim(rtrim($entry->nodeValue)) != '' and !preg_match("/setTimeout/",$entry->nodeValue)) { |
133 | $resp_value .= ltrim(rtrim($entry->nodeValue))."|"; | 133 | $resp_value .= ltrim(rtrim($entry->nodeValue))."|"; |
134 | } | 134 | } |
135 | } | 135 | } |
136 | $arr_resp = explode("|", $resp_value); | 136 | $arr_resp = explode("|", $resp_value); |
137 | 137 | ||
138 | if($type == 1) { | 138 | if($type == 1) { |
139 | $strBal = $this->balance(); | 139 | $strBal = $this->balance(); |
140 | if (preg_match("/TRANSAKSI SUKSES/i", $this->resp_str)) { | 140 | if (preg_match("/TRANSAKSI SUKSES/i", $this->resp_str)) { |
141 | if(count($arr_resp) > 14){ | 141 | if(count($arr_resp) > 14){ |
142 | $xml_str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; | 142 | $xml_str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; |
143 | $xml_str .= "<trx_response>"; | 143 | $xml_str .= "<trx_response>"; |
144 | $xml_str .= "<product>$arr_resp[5]</product>"; | 144 | $xml_str .= "<product>$arr_resp[5]</product>"; |
145 | $xml_str .= "<msisdn>$arr_resp[7]</msisdn>"; | 145 | $xml_str .= "<msisdn>$arr_resp[7]</msisdn>"; |
146 | $xml_str .= "<harga>$arr_resp[11]</harga>"; | 146 | $xml_str .= "<harga>$arr_resp[11]</harga>"; |
147 | $xml_str .= "<ref_num>$arr_resp[3]</ref_num>"; | 147 | $xml_str .= "<ref_num>$arr_resp[3]</ref_num>"; |
148 | $xml_str .= "<kode_voucher>$arr_resp[13]</kode_voucher>"; | 148 | $xml_str .= "<kode_voucher>$arr_resp[13]</kode_voucher>"; |
149 | $xml_str .= "<stock>$strBal</stock>"; | 149 | $xml_str .= "<stock>$strBal</stock>"; |
150 | $xml_str .= "<info>$arr_resp[14]</info>"; | 150 | $xml_str .= "<info>$arr_resp[14]</info>"; |
151 | $xml_str .= "</trx_response>"; | 151 | $xml_str .= "</trx_response>"; |
152 | } | 152 | } |
153 | else { | 153 | else { |
154 | $xml_str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; | 154 | $xml_str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; |
155 | $xml_str .= "<trx_response>"; | 155 | $xml_str .= "<trx_response>"; |
156 | $xml_str .= "<info>Error Parsing</info>"; | 156 | $xml_str .= "<info>Error Parsing</info>"; |
157 | $xml_str .= "</trx_response>"; | 157 | $xml_str .= "</trx_response>"; |
158 | } | 158 | } |
159 | } else { | 159 | } else { |
160 | if(count($arr_resp) > 13){ | 160 | if(count($arr_resp) > 13){ |
161 | $xml_str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; | 161 | $xml_str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; |
162 | $xml_str .= "<trx_response>"; | 162 | $xml_str .= "<trx_response>"; |
163 | $xml_str .= "<product>$arr_resp[5]</product>"; | 163 | $xml_str .= "<product>$arr_resp[5]</product>"; |
164 | $xml_str .= "<msisdn>$arr_resp[7]</msisdn>"; | 164 | $xml_str .= "<msisdn>$arr_resp[7]</msisdn>"; |
165 | $xml_str .= "<harga>$arr_resp[11]</harga>"; | 165 | $xml_str .= "<harga>$arr_resp[11]</harga>"; |
166 | $xml_str .= "<stock>$strBal</stock>"; | ||
166 | $xml_str .= "<info>$arr_resp[13]</info>"; | 167 | $xml_str .= "<info>$arr_resp[13]</info>"; |
167 | $xml_str .= "</trx_response>"; | 168 | $xml_str .= "</trx_response>"; |
168 | } | 169 | } |
169 | else { | 170 | else { |
170 | $xml_str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; | 171 | $xml_str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; |
171 | $xml_str .= "<trx_response>"; | 172 | $xml_str .= "<trx_response>"; |
172 | $xml_str .= "<info>Error Parsing</info>"; | 173 | $xml_str .= "<info>Error Parsing</info>"; |
173 | $xml_str .= "</trx_response>"; | 174 | $xml_str .= "</trx_response>"; |
174 | } | 175 | } |
175 | } | 176 | } |
176 | 177 | ||
177 | $this->resp_xml = $xml_str; | 178 | $this->resp_xml = $xml_str; |
178 | # hit response transaksi ke ST24 | 179 | # hit response transaksi ke ST24 |
179 | #$this->send_form($this->resp_target, '', $arr_resp); | ||
180 | } | 180 | } |
181 | else { | 181 | else { |
182 | preg_match("/name=\"_sourcePage\" value=\"(\\S+)\"/s", $this->resp_str, $matches); | 182 | preg_match("/name=\"_sourcePage\" value=\"(\\S+)\"/s", $this->resp_str, $matches); |
183 | $this->source_page = $matches[1]; | 183 | $this->source_page = $matches[1]; |
184 | 184 | ||
185 | preg_match("/name=\"__fp\" value=\"(\\S+)\"/s", $this->resp_str, $matches2); | 185 | preg_match("/name=\"__fp\" value=\"(\\S+)\"/s", $this->resp_str, $matches2); |
186 | $this->fp = $matches2[1]; | 186 | $this->fp = $matches2[1]; |
187 | } | 187 | } |
188 | } | 188 | } |
189 | } | 189 | } |
190 | 190 | ||
191 | function balance() { | 191 | function balance() { |
192 | $dom = new DOMDocument; | 192 | $dom = new DOMDocument; |
193 | libxml_use_internal_errors(true); | 193 | libxml_use_internal_errors(true); |
194 | if (!@$dom->loadHTML($this->resp_str)) | 194 | if (!@$dom->loadHTML($this->resp_str)) |
195 | { | 195 | { |
196 | $errors=""; | 196 | $errors=""; |
197 | foreach (libxml_get_errors() as $error) { | 197 | foreach (libxml_get_errors() as $error) { |
198 | $errors.=$error->message."\n"; | 198 | $errors.=$error->message."\n"; |
199 | } | 199 | } |
200 | libxml_clear_errors(); | 200 | libxml_clear_errors(); |
201 | print "libxml errors: $errors \n"; | 201 | print "libxml errors: $errors \n"; |
202 | return; | 202 | return; |
203 | } | 203 | } |
204 | 204 | ||
205 | $xpath = new DOMXPath($dom); | 205 | $xpath = new DOMXPath($dom); |
206 | $entries = $xpath->query("//div[@id='header']/table[@width='98%']/tr/td[@align='center']"); | 206 | $entries = $xpath->query("//div[@id='header']/table[@width='98%']/tr/td[@align='center']"); |
207 | 207 | ||
208 | $resp_value = ''; | 208 | $resp_value = ''; |
209 | foreach ($entries as $entry) { | 209 | foreach ($entries as $entry) { |
210 | if(ltrim(rtrim($entry->nodeValue)) != '' ) { | 210 | if(ltrim(rtrim($entry->nodeValue)) != '' ) { |
211 | $resp_value .= $entry->nodeValue; | 211 | $resp_value .= $entry->nodeValue; |
212 | } | 212 | } |
213 | } | 213 | } |
214 | $resp_value = ltrim(rtrim($resp_value)); | 214 | $resp_value = ltrim(rtrim($resp_value)); |
215 | 215 | ||
216 | #print $resp_value."\n"; | 216 | #print $resp_value."\n"; |
217 | # Stock Anda Saat ini : ; 10K = 1; 20K = 1; 25K = 0; 50K = 1; 100K = 1; 150K = 1; 200K = 1; 300K = 1; 500K = 1 | 217 | # Stock Anda Saat ini : ; 10K = 1; 20K = 1; 25K = 0; 50K = 1; 100K = 1; 150K = 1; 200K = 1; 300K = 1; 500K = 1 |
218 | #preg_match("/^Stock Anda Saat ini : ; (\\S+) = (\\S+); (\\S+) = (\\S+); (\\S+) = (\\S+); (\\S+) = (\\S+); (\\S+) = (\\S+); (\\S+) = (\\S+); (\\S+) = (\\S+); (\\S+) = (\\S+); (\\S+) = (\\S+)/s", $resp_value, $matches); | 218 | #preg_match("/^Stock Anda Saat ini : ; (\\S+) = (\\S+); (\\S+) = (\\S+); (\\S+) = (\\S+); (\\S+) = (\\S+); (\\S+) = (\\S+); (\\S+) = (\\S+); (\\S+) = (\\S+); (\\S+) = (\\S+); (\\S+) = (\\S+)/s", $resp_value, $matches); |
219 | #print_r($matches); | 219 | #print_r($matches); |
220 | #$arr_stk = array(); | 220 | #$arr_stk = array(); |
221 | #$arr_stk[$matches[1]] = $matches[2]; | 221 | #$arr_stk[$matches[1]] = $matches[2]; |
222 | #$arr_stk[$matches[3]] = $matches[4]; | 222 | #$arr_stk[$matches[3]] = $matches[4]; |
223 | #$arr_stk[$matches[5]] = $matches[6]; | 223 | #$arr_stk[$matches[5]] = $matches[6]; |
224 | #$arr_stk[$matches[7]] = $matches[8]; | 224 | #$arr_stk[$matches[7]] = $matches[8]; |
225 | #$arr_stk[$matches[9]] = $matches[10]; | 225 | #$arr_stk[$matches[9]] = $matches[10]; |
226 | #$arr_stk[$matches[11]] = $matches[12]; | 226 | #$arr_stk[$matches[11]] = $matches[12]; |
227 | #$arr_stk[$matches[13]] = $matches[14]; | 227 | #$arr_stk[$matches[13]] = $matches[14]; |
228 | #$arr_stk[$matches[15]] = $matches[16]; | 228 | #$arr_stk[$matches[15]] = $matches[16]; |
229 | #$arr_stk[$matches[17]] = $matches[18]; | 229 | #$arr_stk[$matches[17]] = $matches[18]; |
230 | #return $arr_stk; | 230 | #return $arr_stk; |
231 | 231 | ||
232 | preg_match("/^Stock Anda Saat ini : ; (\\S+ \= \\S+ \\S+ \= \\S+ \\S+ \= \\S+ \\S+ \= \\S+ \\S+ \= \\S+ \\S+ \= \\S+ \\S+ \= \\S+ \\S+ \= \\S+ \\S+ \= \\S+)/s", $resp_value, $matches); | 232 | preg_match("/^Stock Anda Saat ini : ; (\\S+ \= \\S+ \\S+ \= \\S+ \\S+ \= \\S+ \\S+ \= \\S+ \\S+ \= \\S+ \\S+ \= \\S+ \\S+ \= \\S+ \\S+ \= \\S+ \\S+ \= \\S+)/s", $resp_value, $matches); |
233 | return $matches[1]; | 233 | return $matches[1]; |
234 | } | 234 | } |
235 | 235 | ||
236 | function send_form($url, $url_ref, $fields){ | 236 | function send_form($url, $url_ref, $fields){ |
237 | 237 | ||
238 | $postvars = ""; | 238 | $postvars = ""; |
239 | foreach($fields as $k => $v) | 239 | foreach($fields as $k => $v) |
240 | { | 240 | { |
241 | $postvars .= $k . '='.$v.'&'; | 241 | $postvars .= $k . '='.$v.'&'; |
242 | } | 242 | } |
243 | $postvars = rtrim($postvars, '&'); | 243 | $postvars = rtrim($postvars, '&'); |
244 | 244 | ||
245 | if (!function_exists('curl_init')){ | 245 | if (!function_exists('curl_init')){ |
246 | die('Sorry cURL is not installed!'); | 246 | die('Sorry cURL is not installed!'); |
247 | } | 247 | } |
248 | 248 | ||
249 | $ch = curl_init(); | 249 | $ch = curl_init(); |
250 | curl_setopt($ch, CURLOPT_URL,$url); | 250 | curl_setopt($ch, CURLOPT_URL,$url); |
251 | curl_setopt($ch, CURLOPT_REFERER, $url_ref); | 251 | curl_setopt($ch, CURLOPT_REFERER, $url_ref); |
252 | curl_setopt($ch, CURLOPT_USERAGENT, $this->getRandomUserAgent()); | 252 | curl_setopt($ch, CURLOPT_USERAGENT, $this->getRandomUserAgent()); |
253 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); | 253 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
254 | curl_setopt($ch, CURLOPT_HEADER, 1); | 254 | curl_setopt($ch, CURLOPT_HEADER, 1); |
255 | 255 | ||
256 | curl_setopt($ch, CURLOPT_COOKIE, "JSESSIONID=".$this->getSessionId()); | 256 | curl_setopt($ch, CURLOPT_COOKIE, "JSESSIONID=".$this->getSessionId()); |
257 | curl_setopt($ch, CURLOPT_POST, count($fields)); | 257 | curl_setopt($ch, CURLOPT_POST, count($fields)); |
258 | curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars); | 258 | curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars); |
259 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | 259 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
260 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); | 260 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); |
261 | unset($postvars); | 261 | unset($postvars); |
262 | 262 | ||
263 | ob_start(); | 263 | ob_start(); |
264 | $resp_str = curl_exec($ch); | 264 | $resp_str = curl_exec($ch); |
265 | ob_end_clean(); | 265 | ob_end_clean(); |
266 | 266 | ||
267 | $date = date("Y-m-d H:i:s"); | 267 | $date = date("Y-m-d H:i:s"); |
268 | if(!curl_errno($ch)) | 268 | if(!curl_errno($ch)) |
269 | { | 269 | { |
270 | $info = curl_getinfo($ch); | 270 | $info = curl_getinfo($ch); |
271 | $log = "[$date] Took " . $info['total_time'] . ' seconds to send a request to ' . $info['url']."\n"; | 271 | $log = "[$date] Took " . $info['total_time'] . ' seconds to send a request to ' . $info['url']."\n"; |
272 | } else { | 272 | } else { |
273 | $log = "[$date] error" . curl_errno($ch)."\n"; | 273 | $log = "[$date] error" . curl_errno($ch)."\n"; |
274 | } | 274 | } |
275 | 275 | ||
276 | $fd = fopen("scrapper_kisel.log", "a+"); | 276 | $fd = fopen("scrapper_kisel.log", "a+"); |
277 | fwrite($fd, $log); | 277 | fwrite($fd, $log); |
278 | fclose($fd); | 278 | fclose($fd); |
279 | curl_close ($ch); | 279 | curl_close ($ch); |
280 | $this->resp_str = $resp_str; | 280 | $this->resp_str = $resp_str; |
281 | return 1; | 281 | return 1; |
282 | 282 | ||
283 | } | 283 | } |
284 | 284 | ||
285 | function setSessionId($session_id){ | 285 | function setSessionId($session_id){ |
286 | $this->session_id = $session_id; | 286 | $this->session_id = $session_id; |
287 | } | 287 | } |
288 | 288 | ||
289 | function getSessionId() { | 289 | function getSessionId() { |
290 | return $this->session_id; | 290 | return $this->session_id; |
291 | } | 291 | } |
292 | 292 | ||
293 | 293 | ||
294 | function do_logout($sess_id) { | 294 | function do_logout($sess_id) { |
295 | if (!function_exists('curl_init')){ | 295 | if (!function_exists('curl_init')){ |
296 | die('Sorry cURL is not installed!'); | 296 | die('Sorry cURL is not installed!'); |
297 | } | 297 | } |
298 | 298 | ||
299 | $ch = curl_init(); | 299 | $ch = curl_init(); |
300 | curl_setopt($ch, CURLOPT_URL, $url); | 300 | curl_setopt($ch, CURLOPT_URL, $url); |
301 | curl_setopt($ch, CURLOPT_REFERER, $url_ref); | 301 | curl_setopt($ch, CURLOPT_REFERER, $url_ref); |
302 | curl_setopt($ch, CURLOPT_USERAGENT, $this->getRandomUserAgent()); | 302 | curl_setopt($ch, CURLOPT_USERAGENT, $this->getRandomUserAgent()); |
303 | curl_setopt($ch, CURLOPT_HEADER, 1); | 303 | curl_setopt($ch, CURLOPT_HEADER, 1); |
304 | curl_setopt($ch, CURLOPT_COOKIE, "JSESSIONID=".$this->get_sessionid()); | 304 | curl_setopt($ch, CURLOPT_COOKIE, "JSESSIONID=".$this->get_sessionid()); |
305 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | 305 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
306 | curl_exec($ch); | 306 | curl_exec($ch); |
307 | curl_close($ch); | 307 | curl_close($ch); |
308 | } | 308 | } |
309 | 309 | ||
310 | } | 310 | } |
311 | 311 | ||
312 | ?> | 312 | ?> |