├── README
├── LICENSE
├── client.php
└── jymengine.class.php
/README:
--------------------------------------------------------------------------------
1 | A PHP SDK and example for using the Yahoo! Messenger API (http://developer.yahoo.com/messenger/)
2 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | oftware Copyright License Agreement (BSD License)
2 |
3 | Copyright (c) 2010, Yahoo! Inc.
4 | All rights reserved.
5 |
6 | Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7 |
8 | * Redistributions of source code must retain the above
9 | copyright notice, this list of conditions and the
10 | following disclaimer.
11 |
12 | * Redistributions in binary form must reproduce the above
13 | copyright notice, this list of conditions and the
14 | following disclaimer in the documentation and/or other
15 | materials provided with the distribution.
16 |
17 | * Neither the name of Yahoo! Inc. nor the names of its
18 | contributors may be used to endorse or promote products
19 | derived from this software without specific prior
20 | written permission of Yahoo! Inc.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 |
24 |
--------------------------------------------------------------------------------
/client.php:
--------------------------------------------------------------------------------
1 | debug = false;
38 |
39 | if ($engine->debug) echo '> Fetching request token'. PHP_EOL;
40 | if (!$engine->fetch_request_token()) die('Fetching request token failed');
41 |
42 | if ($engine->debug) echo '> Fetching access token'. PHP_EOL;
43 | if (!$engine->fetch_access_token()) die('Fetching access token failed');
44 |
45 | if ($engine->debug) echo '> Signon as: '. USERNAME. PHP_EOL;
46 | if (!$engine->signon('I am login from PHP code')) die('Signon failed');
47 |
48 | $seq = -1;
49 | while (true)
50 | {
51 | $resp = $engine->fetch_long_notification($seq+1);
52 | if (isset($resp))
53 | {
54 | if ($resp === false)
55 | {
56 | if ($engine->get_error() != -10)
57 | {
58 | if ($engine->debug) echo '> Fetching access token'. PHP_EOL;
59 | if (!$engine->fetch_access_token()) die('Fetching access token failed');
60 |
61 | if ($engine->debug) echo '> Signon as: '. USERNAME. PHP_EOL;
62 | if (!$engine->signon(date('H:i:s'))) die('Signon failed');
63 |
64 | $seq = -1;
65 | }
66 | continue;
67 | }
68 |
69 |
70 | foreach ($resp as $row)
71 | {
72 | foreach ($row as $key=>$val)
73 | {
74 | if ($val['sequence'] > $seq) $seq = intval($val['sequence']);
75 |
76 | /*
77 | * do actions
78 | */
79 | if ($key == 'buddyInfo') //contact list
80 | {
81 | if (!isset($val['contact'])) continue;
82 |
83 | if ($engine->debug) echo PHP_EOL. 'Contact list: '. PHP_EOL;
84 | foreach ($val['contact'] as $item)
85 | {
86 | if ($engine->debug) echo $item['sender']. PHP_EOL;
87 | }
88 | if ($engine->debug) echo '----------'. PHP_EOL;
89 | }
90 |
91 | else if ($key == 'message') //incoming message
92 | {
93 | if ($engine->debug) echo '+ Incoming message from: "'. $val['sender']. '" on "'. date('H:i:s', $val['timeStamp']). '"'. PHP_EOL;
94 | if ($engine->debug) echo ' '. $val['msg']. PHP_EOL;
95 | if ($engine->debug) echo '----------'. PHP_EOL;
96 |
97 | //reply
98 | $words = explode(' ', trim(strtolower($val['msg'])));
99 | if ($words[0] == 'help')
100 | {
101 | $out = 'This is Yahoo! Open API demo'. PHP_EOL;
102 | $out .= ' To get recent news from yahoo type: news'. PHP_EOL;
103 | $out .= ' To get recent entertainment news from yahoo type: omg'. PHP_EOL;
104 | $out .= ' To change my/robot status type: status newstatus'. PHP_EOL;
105 | }
106 | else if ($words[0] == 'news')
107 | {
108 | if ($engine->debug) echo '> Retrieving news rss'. PHP_EOL;
109 | $rss = file_get_contents('http://rss.news.yahoo.com/rss/topstories');
110 |
111 | if (preg_match_all('|
(.*?)|is', $rss, $m))
112 | {
113 | $out = 'Recent Yahoo News:'. PHP_EOL;
114 | for ($i=2; $i<7; $i++)
115 | {
116 | $out .= str_replace("\n", ' ', $m[1][$i]). PHP_EOL;
117 | }
118 | }
119 | }
120 | else if ($words[0] == 'omg')
121 | {
122 | if ($engine->debug) echo '> Retrieving OMG news rss'. PHP_EOL;
123 | $rss = file_get_contents('http://rss.omg.yahoo.com/latest/news/');
124 |
125 | if (preg_match_all('|(.*?)|is', $rss, $m))
126 | {
127 | $out = 'Recent OMG News:'. PHP_EOL;
128 | for ($i=2; $i<7; $i++)
129 | {
130 | $out .= str_replace(array(''), array('', ''), $m[1][$i]). PHP_EOL;
131 | }
132 | }
133 | }
134 | else if ($words[0] == 'status')
135 | {
136 | $engine->change_presence(str_replace('status ', '', strtolower($val['msg'])));
137 | $out = 'My status is changed';
138 | }
139 | else
140 | {
141 | $out = 'Please type: help';
142 | }
143 |
144 | //send message
145 | if ($engine->debug) echo '> Sending reply message '. PHP_EOL;
146 | if ($engine->debug) echo ' '. $out. PHP_EOL;
147 | if ($engine->debug) echo '----------'. PHP_EOL;
148 | $engine->send_message($val['sender'], json_encode($out));
149 | }
150 |
151 | else if ($key == 'buddyAuthorize') //incoming contact request
152 | {
153 | if ($engine->debug) echo PHP_EOL. 'Accept buddy request from: '. $val['sender']. PHP_EOL;
154 | if ($engine->debug) echo '----------'. PHP_EOL;
155 | if (!$engine->response_contact($val['sender'], true, 'Welcome to my list'))
156 | {
157 | $engine->delete_contact($val['sender']);
158 | $engine->response_contact($val['sender'], true, 'Welcome to my list');
159 | }
160 | }
161 | }
162 | }
163 | }
164 | }
165 |
166 | ?>
167 |
--------------------------------------------------------------------------------
/jymengine.class.php:
--------------------------------------------------------------------------------
1 | _config['consumer_key'] = $consumer_key;
58 | $this->_config['secret_key'] = $secret_key;
59 | $this->_config['username'] = $username;
60 | $this->_config['password'] = $password;
61 |
62 | $this->_ym = array();
63 | $this->_error = null;
64 | }
65 |
66 | public function fetch_request_token()
67 | {
68 | //prepare url
69 | $url = $this::URL_OAUTH_DIRECT;
70 | $url .= '?login='. $this->_config['username'];
71 | $url .= '&passwd='. $this->_config['password'];
72 | $url .= '&oauth_consumer_key='. $this->_config['consumer_key'];
73 | $rs = $this->curl($url);
74 |
75 | if (stripos($rs, 'RequestToken') === false) return false;
76 | $request_token = trim(str_replace('RequestToken=', '', $rs));
77 | $this->_token['request'] = $request_token;
78 |
79 | return true;
80 | }
81 |
82 | public function fetch_access_token()
83 | {
84 | //prepare url
85 | $url = $this::URL_OAUTH_ACCESS_TOKEN;
86 | $url .= '?oauth_consumer_key='. $this->_config['consumer_key'];
87 | $url .= '&oauth_nonce='. uniqid(rand());
88 | $url .= '&oauth_signature='. $this->_config['secret_key']. '%26';
89 | $url .= '&oauth_signature_method=PLAINTEXT';
90 | $url .= '&oauth_timestamp='. time();
91 | $url .= '&oauth_token='. $this->_token['request'];
92 | $url .= '&oauth_version=1.0';
93 | $rs = $this->curl($url);
94 |
95 | if (stripos($rs, 'oauth_token') === false)
96 | {
97 | $this->_error = $rs;
98 | return false;
99 | }
100 |
101 | //parse access token
102 | $tmp = explode('&', $rs);
103 | foreach ($tmp as $row)
104 | {
105 | $col = explode('=', $row);
106 | $access_token[$col[0]] = $col[1];
107 | }
108 |
109 | $this->_token['access'] = $access_token;
110 |
111 | return true;
112 | }
113 |
114 | public function fetch_crumb()
115 | {
116 | //prepare url
117 | $url = $this::URL_YM_SESSION;
118 | $url .= '?oauth_consumer_key='. $this->_config['consumer_key'];
119 | $url .= '&oauth_nonce='. uniqid(rand());
120 | $url .= '&oauth_signature='. $this->_config['secret_key']. '%26'. $this->_token['access']['oauth_token_secret'];
121 | $url .= '&oauth_signature_method=PLAINTEXT';
122 | $url .= '&oauth_timestamp='. time();
123 | $url .= '&oauth_token='. $this->_token['access']['oauth_token'];
124 | $url .= '&oauth_version=1.0';
125 |
126 | //additional header
127 | $header[] = 'Content-type: application/json; charset=utf-8';
128 | $rs = $this->curl($url, 'get', $header);
129 |
130 | if (stripos($rs, 'crumb') === false) return false;
131 |
132 | $js = json_decode($rs, true);
133 | $this->_ym['crumb'] = $js;
134 |
135 | return true;
136 | }
137 |
138 | public function signon($status = '', $state = 0)
139 | {
140 | //prepare url
141 | $url = $this::URL_YM_SESSION;
142 | $url .= '?oauth_consumer_key='. $this->_config['consumer_key'];
143 | $url .= '&oauth_nonce='. uniqid(rand());
144 | $url .= '&oauth_signature='. $this->_config['secret_key']. '%26'. $this->_token['access']['oauth_token_secret'];
145 | $url .= '&oauth_signature_method=PLAINTEXT';
146 | $url .= '&oauth_timestamp='. time();
147 | $url .= '&oauth_token='. $this->_token['access']['oauth_token'];
148 | $url .= '&oauth_version=1.0';
149 | $url .= '¬ifyServerToken=1';
150 |
151 | //additional header
152 | $header[] = 'Content-type: application/json; charset=utf-8';
153 | $postdata = '{"presenceState" : '. $state. ', "presenceMessage" : "'. $status. '"}';
154 | $this->includeheader = true;
155 | $rs = $this->curl($url, 'post', $header, $postdata);
156 | $this->includeheader = false;
157 | list($header, $body) = explode("\r\n\r\n", $rs, 2);
158 |
159 | //get IM cookie
160 | $notifytoken = '';
161 | if (preg_match('/set-cookie: IM=(.+?); expires/', $header, $m))
162 | $notifytoken = $m[1];
163 |
164 | if (stripos($body, 'sessionId') === false) return false;
165 |
166 | $js = json_decode($body, true);
167 | $js['notifytoken'] = $notifytoken;
168 | $this->_ym['signon'] = $js;
169 |
170 | return true;
171 | }
172 |
173 | public function signoff()
174 | {
175 | //prepare url
176 | $url = $this::URL_YM_SESSION;
177 | $url .= '?oauth_consumer_key='. $this->_config['consumer_key'];
178 | $url .= '&oauth_nonce='. uniqid(rand());
179 | $url .= '&oauth_signature='. $this->_config['secret_key']. '%26'. $this->_token['access']['oauth_token_secret'];
180 | $url .= '&oauth_signature_method=PLAINTEXT';
181 | $url .= '&oauth_timestamp='. time();
182 | $url .= '&oauth_token='. $this->_token['access']['oauth_token'];
183 | $url .= '&oauth_version=1.0';
184 | $url .= '&sid='. $this->_ym['signon']['sessionId'];
185 |
186 | //additional header
187 | $header[] = 'Content-type: application/json; charset=utf-8';
188 | $rs = $this->curl($url, 'delete', $header);
189 |
190 | return true;
191 | }
192 |
193 | public function change_presence($status = '', $state = 0)
194 | {
195 | //prepare url
196 | $url = $this::URL_YM_PRESENCE;
197 | $url .= '?oauth_consumer_key='. $this->_config['consumer_key'];
198 | $url .= '&oauth_nonce='. uniqid(rand());
199 | $url .= '&oauth_signature='. $this->_config['secret_key']. '%26'. $this->_token['access']['oauth_token_secret'];
200 | $url .= '&oauth_signature_method=PLAINTEXT';
201 | $url .= '&oauth_timestamp='. time();
202 | $url .= '&oauth_token='. $this->_token['access']['oauth_token'];
203 | $url .= '&oauth_version=1.0';
204 | $url .= '&sid='. $this->_ym['signon']['sessionId'];
205 |
206 | //additional header
207 | $header[] = 'Content-type: application/json; charset=utf-8';
208 | $postdata = '{"presenceState" : '. $state. ', "presenceMessage" : "'. $status. '"}';
209 | $rs = $this->curl($url, 'put', $header, $postdata);
210 |
211 | return true;
212 | }
213 |
214 | public function send_message($user, $message)
215 | {
216 | //prepare url
217 | $url = $this::URL_YM_MESSAGE;
218 | $url .= '?oauth_consumer_key='. $this->_config['consumer_key'];
219 | $url .= '&oauth_nonce='. uniqid(rand());
220 | $url .= '&oauth_signature='. $this->_config['secret_key']. '%26'. $this->_token['access']['oauth_token_secret'];
221 | $url .= '&oauth_signature_method=PLAINTEXT';
222 | $url .= '&oauth_timestamp='. time();
223 | $url .= '&oauth_token='. $this->_token['access']['oauth_token'];
224 | $url .= '&oauth_version=1.0';
225 | $url .= '&sid='. $this->_ym['signon']['sessionId'];
226 | $url = str_replace('{{USER}}', $user, $url);
227 |
228 | //additional header
229 | $header[] = 'Content-type: application/json; charset=utf-8';
230 | $postdata = '{"message" : '. $message. '}';
231 |
232 | $rs = $this->curl($url, 'post', $header, $postdata);
233 |
234 | return true;
235 | }
236 |
237 | public function fetch_contact_list()
238 | {
239 | //prepare url
240 | $url = $this::URL_YM_CONTACT;
241 | $url .= '?oauth_consumer_key='. $this->_config['consumer_key'];
242 | $url .= '&oauth_nonce='. uniqid(rand());
243 | $url .= '&oauth_signature='. $this->_config['secret_key']. '%26'. $this->_token['access']['oauth_token_secret'];
244 | $url .= '&oauth_signature_method=PLAINTEXT';
245 | $url .= '&oauth_timestamp='. time();
246 | $url .= '&oauth_token='. $this->_token['access']['oauth_token'];
247 | $url .= '&oauth_version=1.0';
248 | $url .= '&sid='. $this->_ym['signon']['sessionId'];
249 | $url .= '&fields=%2Bpresence';
250 | $url .= '&fields=%2Bgroups';
251 |
252 | //additional header
253 | $header[] = 'Content-type: application/json; charset=utf-8';
254 | $rs = $this->curl($url, 'get', $header);
255 |
256 | if (stripos($rs, 'contact') === false) return false;
257 |
258 | $js = json_decode($rs, true);
259 |
260 | return $js['contacts'];
261 | }
262 |
263 | public function add_contact($user, $group = 'Friends', $message = '')
264 | {
265 | //prepare url
266 | $url = $this::URL_YM_GROUP;
267 | $url .= '?oauth_consumer_key='. $this->_config['consumer_key'];
268 | $url .= '&oauth_nonce='. uniqid(rand());
269 | $url .= '&oauth_signature='. $this->_config['secret_key']. '%26'. $this->_token['access']['oauth_token_secret'];
270 | $url .= '&oauth_signature_method=PLAINTEXT';
271 | $url .= '&oauth_timestamp='. time();
272 | $url .= '&oauth_token='. $this->_token['access']['oauth_token'];
273 | $url .= '&oauth_version=1.0';
274 | $url .= '&sid='. $this->_ym['signon']['sessionId'];
275 | $url = str_replace('{{GROUP}}', $group, $url);
276 | $url = str_replace('{{USER}}', $user, $url);
277 |
278 | //additional header
279 | $header[] = 'Content-type: application/json; charset=utf-8';
280 | $postdata = '{"message" : "'. $message. '"}';
281 | $rs = $this->curl($url, 'put', $header, $postdata);
282 |
283 | return true;
284 | }
285 |
286 | public function delete_contact($user, $group = 'Friends')
287 | {
288 | //prepare url
289 | $url = $this::URL_YM_GROUP;
290 | $url .= '?oauth_consumer_key='. $this->_config['consumer_key'];
291 | $url .= '&oauth_nonce='. uniqid(rand());
292 | $url .= '&oauth_signature='. $this->_config['secret_key']. '%26'. $this->_token['access']['oauth_token_secret'];
293 | $url .= '&oauth_signature_method=PLAINTEXT';
294 | $url .= '&oauth_timestamp='. time();
295 | $url .= '&oauth_token='. $this->_token['access']['oauth_token'];
296 | $url .= '&oauth_version=1.0';
297 | $url .= '&sid='. $this->_ym['signon']['sessionId'];
298 | $url = str_replace('{{GROUP}}', $group, $url);
299 | $url = str_replace('{{USER}}', $user, $url);
300 |
301 | //additional header
302 | $header[] = 'Content-type: application/json; charset=utf-8';
303 | $rs = $this->curl($url, 'delete', $header);
304 |
305 | return true;
306 | }
307 |
308 | public function response_contact($user, $accept = true, $message = '')
309 | {
310 | if ($accept)
311 | {
312 | $method = 'POST';
313 | $message == '' ? $reason = 'Welcome' : $reason = $message;
314 | }
315 | else
316 | {
317 | $method = 'DELETE';
318 | $message == '' ? $reason = 'No thanks' : $reason = $message;
319 | }
320 |
321 | //prepare url
322 | $url = $this::URL_YM_BUDDYREQUEST;
323 | $url .= '?oauth_consumer_key='. $this->_config['consumer_key'];
324 | $url .= '&oauth_nonce='. uniqid(rand());
325 | $url .= '&oauth_signature='. $this->_config['secret_key']. '%26'. $this->_token['access']['oauth_token_secret'];
326 | $url .= '&oauth_signature_method=PLAINTEXT';
327 | $url .= '&oauth_timestamp='. time();
328 | $url .= '&oauth_token='. $this->_token['access']['oauth_token'];
329 | $url .= '&oauth_version=1.0';
330 | $url .= '&sid='. $this->_ym['signon']['sessionId'];
331 | $url = str_replace('{{USER}}', $user, $url);
332 |
333 | //additional header
334 | $header[] = 'Content-type: application/json; charset=utf-8';
335 | $postdata = '{"authReason" : "'. $reason. '"}';
336 | $this->includeheader = true;
337 | $rs = $this->curl($url, strtolower($method), $header, $postdata);
338 | $this->includeheader = true;
339 |
340 | if (strpos($rs, "\r\n\r\n") === false)
341 | {
342 | $this->_error = -20;
343 | return false;
344 | }
345 |
346 | list($header, $body) = explode("\r\n\r\n", $rs, 2);
347 |
348 | //get status code
349 | $code = '';
350 | if (preg_match('|HTTP/1.1 (.*?) OK|', $header, $m))
351 | $code = $m[1];
352 |
353 | if ($code != 200)
354 | {
355 | $this->_error = $code;
356 | return false;
357 | }
358 |
359 | return true;
360 | }
361 |
362 | public function fetch_notification($seq = 0)
363 | {
364 | //prepare url
365 | $url = $this::URL_YM_NOTIFICATION;
366 | $url .= '?oauth_consumer_key='. $this->_config['consumer_key'];
367 | $url .= '&oauth_nonce='. uniqid(rand());
368 | $url .= '&oauth_signature='. $this->_config['secret_key']. '%26'. $this->_token['access']['oauth_token_secret'];
369 | $url .= '&oauth_signature_method=PLAINTEXT';
370 | $url .= '&oauth_timestamp='. time();
371 | $url .= '&oauth_token='. $this->_token['access']['oauth_token'];
372 | $url .= '&oauth_version=1.0';
373 | $url .= '&sid='. $this->_ym['signon']['sessionId'];
374 | $url .= '&seq='. intval($seq);
375 | $url .= '&count=100';
376 |
377 | //additional header
378 | $header[] = 'Content-type: application/json; charset=utf-8';
379 | $rs = $this->curl($url, 'get', $header);
380 |
381 | $js = json_decode($rs, true);
382 |
383 | if (isset($js['error']))
384 | {
385 | $this->_error = $js['error'];
386 | return false;
387 | }
388 |
389 | if (stripos($rs, 'pendingMsg') === false) return false;
390 | if (count($js['responses']) < 1) return false;
391 |
392 | $this->_error = null;
393 | return $js['responses'];
394 | }
395 |
396 | public function fetch_long_notification($seq = 0)
397 | {
398 | //prepare url
399 | $url = $this::URL_YM_NOTIFICATION_LONG;
400 | $url .= '?oauth_consumer_key='. $this->_config['consumer_key'];
401 | $url .= '&oauth_nonce='. uniqid(rand());
402 | $url .= '&oauth_signature='. $this->_config['secret_key']. '%26'. $this->_token['access']['oauth_token_secret'];
403 | $url .= '&oauth_signature_method=PLAINTEXT';
404 | $url .= '&oauth_timestamp='. time();
405 | $url .= '&oauth_token='. $this->_token['access']['oauth_token'];
406 | $url .= '&oauth_version=1.0';
407 | $url .= '&sid='. $this->_ym['signon']['sessionId'];
408 | $url .= '&seq='. intval($seq);
409 | $url .= '&format=json';
410 | $url .= '&count=100';
411 | $url .= '&idle=120';
412 | $url .= '&rand='. uniqid(rand());
413 | $url .= '&IM='. $this->_ym['signon']['notifytoken'];
414 |
415 | $url = str_replace('{{NOTIFICATION_SERVER}}', $this->_ym['signon']['notifyServer'], $url);
416 | $url = str_replace('{{USER}}', $this->_ym['signon']['primaryLoginId'], $url);
417 |
418 | //additional header
419 | $header[] = 'Content-type: application/json; charset=utf-8';
420 | $header[] = 'Connection: keep-alive';
421 |
422 | $this->includeheader = true;
423 | $rs = $this->curl($url, 'get', $header, null, 160);
424 | $this->includeheader = false;
425 |
426 | if (strpos($rs, "\r\n\r\n") === false)
427 | {
428 | $this->_error = -20;
429 | return false;
430 | }
431 |
432 | list($header, $body) = explode("\r\n\r\n", $rs, 2);
433 |
434 | //get status code
435 | $code = '';
436 | if (preg_match('|HTTP/1.1 (.*?) OK|', $header, $m))
437 | $code = $m[1];
438 |
439 | if ($code != 200)
440 | {
441 | $this->_error = $code;
442 | return false;
443 | }
444 |
445 | if ($body == '')
446 | {
447 | $this->_error = -10;
448 | return false;
449 | }
450 |
451 | $js = json_decode($body, true);
452 |
453 | if (isset($js['error']))
454 | {
455 | $this->_error = $js['error'];
456 | return false;
457 | }
458 |
459 | $this->_error = null;
460 | return $js['responses'];
461 | }
462 |
463 |
464 |
465 |
466 | /*
467 | * fetch url using curl
468 | */
469 | private function curl($url, $method = 'get', $header = null, $postdata = null, $timeout = 60)
470 | {
471 | $s = curl_init();
472 |
473 | curl_setopt($s,CURLOPT_URL, $url);
474 | if ($header)
475 | curl_setopt($s,CURLOPT_HTTPHEADER, $header);
476 |
477 | if ($this->debug)
478 | curl_setopt($s,CURLOPT_VERBOSE, TRUE);
479 |
480 | curl_setopt($s,CURLOPT_TIMEOUT, $timeout);
481 | curl_setopt($s,CURLOPT_CONNECTTIMEOUT, $timeout);
482 | curl_setopt($s,CURLOPT_MAXREDIRS, 3);
483 | curl_setopt($s,CURLOPT_RETURNTRANSFER, true);
484 | curl_setopt($s,CURLOPT_FOLLOWLOCATION, 1);
485 | curl_setopt($s,CURLOPT_COOKIEJAR, 'cookie.txt');
486 | curl_setopt($s,CURLOPT_COOKIEFILE, 'cookie.txt');
487 |
488 | if(strtolower($method) == 'post')
489 | {
490 | curl_setopt($s,CURLOPT_POST, true);
491 | curl_setopt($s,CURLOPT_POSTFIELDS, $postdata);
492 | }
493 | else if(strtolower($method) == 'delete')
494 | {
495 | curl_setopt($s,CURLOPT_CUSTOMREQUEST, 'DELETE');
496 | }
497 | else if(strtolower($method) == 'put')
498 | {
499 | curl_setopt($s,CURLOPT_CUSTOMREQUEST, 'PUT');
500 | curl_setopt($s,CURLOPT_POSTFIELDS, $postdata);
501 | }
502 |
503 | curl_setopt($s,CURLOPT_HEADER, $this->includeheader);
504 | curl_setopt($s,CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1');
505 | curl_setopt($s, CURLOPT_SSL_VERIFYPEER, false);
506 |
507 | $html = curl_exec($s);
508 | $status = curl_getinfo($s, CURLINFO_HTTP_CODE);
509 |
510 | curl_close($s);
511 |
512 | return $html;
513 | }
514 |
515 | public function get_error()
516 | {
517 | return $this->_error;
518 | }
519 |
520 | }
521 |
522 | ?>
523 |
--------------------------------------------------------------------------------