Return to Snippet

Revision: 2146
at January 4, 2007 11:07 by noname


Initial Code
<?php
  function CheckICQStatus($uin) {
    $fp = fsockopen('status.icq.com', 80, &$errno, &$errstr, 8);
    if (!$fp) {
      return false;
    }
    $request = "HEAD /online.gif?icq=$uin HTTP/1.1
"
             . "Host: status.icq.com
"
             . "Connection: close

";
    fputs($fp, $request);

    // read response if request done
    while (!feof($fp)) {
      $temp = fgets($fp, 128);
      if (strstr($temp, 'Location: ')) {
        $location = str_replace("
", '', $temp);
      }
    }

    // remove some unnesscessary things
    $location = str_replace('Location: ', '', $location);
    $location = str_replace(' ', '', $location);

    $status = $location;
    fclose($fp);

    // return status
    switch ($status) {
      case '/0/online0.gif': return 'offline';
      case '/0/online1.gif': return 'online';
      case '/0/online2.gif': return 'n/a';
    }
  }
?>

//Example:
<?php
  $uin = '123456789'; //the icq number

  //checking
  if ($status = CheckICQStatus($uin)) {
    echo 'Status: ' . $status;
  } else {
    echo 'error!';
  }
?>

Initial URL

                                

Initial Description

                                

Initial Title
read icq status

Initial Tags

                                

Initial Language
PHP