login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > PHP > Handige scripts > ICQ Status Class

ICQ Status Class

Auteur: PHPClasses.org - 28 januari 2005 - 17:55 - Gekeurd door: Maarten - Hits: 3399 - Aantal punten: 5.00 (4 stemmen)



Dit scriptje kan je gebruiken om te controleren of iemand online/offline is op ICQ.

Code:
Deze class zet je op je pagina:
  1. <?php
  2. define ("ICQ_ONLINE", 1);
  3. define ("ICQ_OFFLINE", 2);
  4. define ("ICQ_WEBAWARE", 3);
  5.  
  6. class CICQStatus
  7. {
  8. var $timeout = 20;
  9.  
  10. function execute ($icq = "", &$errno, &$errstr)
  11. {
  12. $errno = "";
  13. $errstr = "";
  14. $raw_headers = "";
  15.  
  16. $icq = trim ($icq);
  17. $host = "status.icq.com";
  18. $path = "/online.gif?icq=" . $icq;
  19.  
  20. if (!function_exists ("fsockopen"))
  21. {
  22. $errno = "-1";
  23. $errstr = "Function fsockopen not founded!";
  24. return false;
  25. }
  26. else
  27. {
  28. $fp = fsockopen ($host, 80, $errno, $errstr, $this->timeout);
  29. if (!$fp)
  30. { return false; }
  31. else
  32. {
  33. fputs ($fp,"GET " . $path . " HTTP/1.1\r\n");
  34. fputs ($fp,"HOST: " . $host . "\r\n");
  35. fputs ($fp,"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)\r\n");
  36. fputs ($fp,"Connection: close\r\n\r\n");
  37.  
  38. while (!feof ($fp))
  39. { $raw_headers .= fgets ($fp, 128); }
  40. }
  41. fclose ($fp);
  42.  
  43. $headers = array ();
  44. $tmp_headers = explode ("\n", $raw_headers);
  45. foreach ($tmp_headers as $header)
  46. {
  47. $tokens = explode (":", $header, 2);
  48. if (isset ($tokens[0]) && (trim($tokens[0]) != ""))
  49. {
  50. if (!isset ($tokens[1])) { $tokens[1] = ""; }
  51. $headers[] = array ($tokens[0] => trim($tokens[1]));
  52. }
  53. }
  54.  
  55. $location = "";
  56. foreach ($headers as $header)
  57. {
  58. if (isset ($header["Location"]))
  59. {
  60. $location = $header["Location"];
  61. break;
  62. }
  63. }
  64.  
  65. $filename = basename ($location);
  66. switch ($filename) {
  67. case "online0.gif":
  68. return ICQ_OFFLINE;
  69. break;
  70. case "online1.gif":
  71. return ICQ_ONLINE;
  72. break;
  73. default:
  74. return ICQ_WEBAWARE;
  75. break;
  76. }
  77. }
  78. }
  79. }
  80. ?>



En zo gebruik je hem:
  1. <?php
  2. $icq_nummer = 303445919;
  3. $icqstatus = new CICQStatus ();
  4. $status = $icqstatus->execute ($icq_nummer, $errno, $errstr);
  5. if ($status)
  6. {
  7. switch ($status) {
  8. case ICQ_ONLINE:
  9. echo ('Online!');
  10. break;
  11. case ICQ_OFFLINE:
  12. echo ('Offline!');
  13. break;
  14. }
  15. }
  16. else // if ($icqstatus->execute ($_GET["icq"], $errno, $errstr))
  17. {
  18. print ("An error occurred during ICQStatus query: <br />");
  19. print ("Error n. " . $errno . ": " . $errstr);
  20. }
  21. ?>
Download code! Download code (.txt)

 Bekijk een voorbeeld van dit script!
 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Lees de reacties (3)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.036s