note 56452 added to function.curl-init
| From: | ru dot dy at gmx dot net | Date: | Fri, 02 Sep 2005 22:10:42 +0000 |
| Subject: | note 56452 added to function.curl-init | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-94678@lists.php.net to get a copy of this message | ||
The curl-functions can be used to check the ICQ-webstatus from an icq-number, to get the status as a
string rather than as one of those standard images provided from ICQ. This can also be used to place
your own Image instead of simple text, to show ones online-status, of course if activated in the
options. The idea behind is to get just the text from the apache-site that would lead us to the
picture that shows the online status. curl does not do any redirect, as long as we don't set
CURLOPT_FOLLOWLOCATION. This is nice because the image can change, as long as the paths and
filenames (contained in the site-text) don't. The different states are stored in a short array
of unsigned crc-values.
<?php
class ICQ {
var $crc = array('253889085' => 'offline', '1177883536' =>
'online', '1182613274' => 'hidden');
//CRCs valid as long as the redirect-page does not change
function getCrc($url) {
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HEADER, 0);
ob_start();
curl_exec ($ch);
curl_close ($ch);
$cache = ob_get_contents();
ob_end_clean();
//print($cache);
return (string)abs(crc32($cache));
}
function status($number) {
$check = $this->getCrc( 'http://status.icq.com/online.gif?icq=' .
$number . '&img=5');
if (in_array($check, array_keys($this->crc))) {
return $this->crc[$check];
}
return false;
}
}
?>
Usage:
<?php
$icq = new ICQ();
print($icq->status('123456789'));
?>
Outputs 'online', 'offline' or 'hidden'.
----
Manual Page -- http://www.php.net/manual/en/function.curl-init.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56452
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56452&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56452&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56452&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56452&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56452&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56452&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56452&report=yes
Search -- http://master.php.net/manage/user-notes.php