Posted By

noname on 01/04/07


Tagged

status icq


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

guerrera
noname
Steffen82
JimiJay
sindrom


read icq status


 / Published in: PHP
 

  1. <?php
  2. function CheckICQStatus($uin) {
  3. $fp = fsockopen('status.icq.com', 80, &$errno, &$errstr, 8);
  4. if (!$fp) {
  5. return false;
  6. }
  7. $request = "HEAD /online.gif?icq=$uin HTTP/1.1
  8. "
  9. . "Host: status.icq.com
  10. "
  11. . "Connection: close
  12.  
  13. ";
  14. fputs($fp, $request);
  15.  
  16. // read response if request done
  17. while (!feof($fp)) {
  18. $temp = fgets($fp, 128);
  19. if (strstr($temp, 'Location: ')) {
  20. $location = str_replace("
  21. ", '', $temp);
  22. }
  23. }
  24.  
  25. // remove some unnesscessary things
  26. $location = str_replace('Location: ', '', $location);
  27. $location = str_replace(' ', '', $location);
  28.  
  29. $status = $location;
  30. fclose($fp);
  31.  
  32. // return status
  33. switch ($status) {
  34. case '/0/online0.gif': return 'offline';
  35. case '/0/online1.gif': return 'online';
  36. case '/0/online2.gif': return 'n/a';
  37. }
  38. }
  39. ?>
  40.  
  41. //Example:
  42. <?php
  43. $uin = '123456789'; //the icq number
  44.  
  45. //checking
  46. if ($status = CheckICQStatus($uin)) {
  47. echo 'Status: ' . $status;
  48. } else {
  49. echo 'error!';
  50. }
  51. ?>

Report this snippet  

You need to login to post a comment.