note 56452 deleted from function.curl-init by googleguy

From: Date: Sat, 19 Jan 2013 03:40:24 +0000
Subject: note 56452 deleted from function.curl-init by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-193217@lists.php.net to get a copy of this message
Note Submitter: ru dot dy at gmx dot net ---- 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'.

« previous php.notes (#193217) next »