Zend - The PHP Company




Miscellaneous

Add Code


ICQ Status Query Function  

Type: code fragment
Added by: sdx
Entered: 24/06/2003
Last modified: 08/12/2003
Rating: - (fewer than 3 votes)
Views: 4119
this function returns the status of a given icq number (online,offline,disabled). after endless looking for an icq status checker in php and discovering some none-working, i found out the easy way icq handles the status images and wrote a small function to parse their reply stuff to a status image query.


<?php

    
/*  
    
        ICQ status checker function - returns 0 when $uin is offline, 1 when online and 2 when
                                      the status indicator is deactivated, 3 on error
    
        by Stefan Dengscherz, 2003 -- http://lock.at -- sd@lock.at
    
    */

    
function icqstatus($uin
    {
        
// establish a connection to the icq status server
        
$fp fsockopen("status.icq.com",80,&$errno,&$errstr,8);
        
        
// error, can't connect to icq status server
        
if (!$fp) return 3;
        
        
// http request - online.gif
        
$request "HEAD /online.gif?icq=".$uin."&img=5 HTTP/1.0rn"
                  
."Host: wwp.icq.comrn"
                  
."Connection: closernrn";
        
        
        
// send request
        
fputs($fp$request);

        
// parse sent data
        
do 
        {
            
$response fgets($fp,1024);
        }
        while (!
feof($fp) && !stristr($response,"Location"));

        
// close connection
        
fclose($fp);

        
// return status depending on sent redirection string
        
        // online
        
if (strstr($response,"online1")) return 1;
        
        
// offline
        
elseif (strstr($response,"online0")) return 0;
        
        
// deactivated
        
elseif (strstr($response,"online2")) return 2;
        
        
// error
        
else return 3;
    }

?>


Usage Example




Rate This Script





Search



This Category All Categories