Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Licznik osób online
Forum PHP.pl > Forum > PHP
radmistrz2
WIem że ten temat w google powtarza się wiele razy, ale żaden nie działa. Ma ktoś jakiś niewielki, w 100% działający licznik gości online??
_olo_1984
w którymś z postów coś takiego widziałem:
  1. <?php
  2. class onlineInfo
  3. {
  4.  
  5. static $dir='.';
  6. static $dataFile;
  7. private $maxLastSeenTime=240;
  8. private $userOnList=false;
  9.  
  10.  
  11. public function __construct()
  12. {
  13.  
  14. self::$dataFile=self::$dir.'/temp/usersOnline.tmp';
  15. if(!file_exists(self::$dataFile))
  16. {
  17. $this->save();
  18. }
  19.  
  20. $this->userIp=$_SERVER['REMOTE_ADDR'];
  21. $this->load();
  22. $this->checkVisitors();
  23. $this->save();
  24.  
  25. }
  26.  
  27. private function load()
  28. {
  29. $this->data=file(self::$dataFile);
  30. $count=count($this->data);
  31. if($count>0)
  32. {
  33.  
  34. for($i=0;$i<$count;++$i)
  35. {
  36. $this->data[$i]=trim($this->data[$i]);
  37. $this->userInfo[$i]=explode("|", $this->data[$i]);
  38. if($this->userInfo[$i][0]==$this->userIp)
  39. {
  40. $this->userOnList=true;
  41. $this->lastAvtivityTime=$this->userInfo[$i][0];
  42. }
  43. }
  44. }
  45.  
  46. if(!$this->userOnList)
  47. {
  48.  
  49. $this->userInfo[$count][0]=$this->userIp;
  50. $this->userInfo[$count][1]=time();
  51. }
  52.  
  53. }
  54.  
  55. function checkVisitors()
  56. {
  57. $count=count($this->userInfo);
  58. $currentTime=time();
  59. if($count>0)
  60. {
  61. for($i=0;$i<$count;++$i)
  62. {
  63. if($this->maxLastSeenTime<=($currentTime-$this->userInfo[$i][1]))
  64. {
  65. if($this->userInfo[$i][0]==$this->userIp)
  66. {
  67. $this->userInfo[$i][1]=time();
  68. continue;
  69. }
  70. unset($this->userInfo[$i]);
  71. }
  72. else
  73. {
  74. if($this->userInfo[$i][0]==$this->userIp)
  75. {
  76. $this->userInfo[$i][1]=time();
  77. }
  78. }
  79. }
  80. }
  81. }
  82.  
  83. public function getVisitors()
  84. {
  85. return count($this->userInfo);
  86. }
  87.  
  88. function save()
  89. {
  90. $string='';
  91. $count=count($this->userInfo);
  92.  
  93. $this->saveArray=array();
  94. $this->userInfo=array_merge($this->saveArray, $this->userInfo);
  95.  
  96. $lineEnd="\n";
  97. if($count>0)
  98. {
  99. for($i=0;$i<$count;++$i)
  100. {
  101. if($i==$count-1)
  102. {
  103. $lineEnd='';
  104. }
  105. if(is_array($this->userInfo[$i]))
  106. {
  107. $string.=implode("|", $this->userInfo[$i]).$lineEnd;
  108. }
  109. }
  110. }
  111. file_put_contents(self::$dataFile, $string);
  112. }
  113. }
  114.  
  115. $oInfo = new onlineInfo();
  116. print 'ilo�c os�b online: '.$oInfo->getVisitors();
  117.  
  118. ?>

może się przyda, pozdr
radmistrz2
nie działa
_olo_1984
Cytat(radmistrz2 @ 10.07.2008, 12:57:49 ) *
nie działa


co to znaczy nie działa ? Jaki objaw, bo ja sprawdzałem i działa.
radmistrz2
Parse error: syntax error, unexpected T_STATIC, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in
mike
Masz PHP4 a podany kod jest na PHP5.
Zainstaluj PHP5 i nie baw się w archeologię tongue.gif
Puzi
Polecam: http://webmade.org/porady/licznik-on-line-php.php

lub

  1. <?php
  2. $minuty=3;
  3. $czas=time()+60*$minuty;
  4. $bazaip = file("online.txt");
  5. $ile=count($bazaip);
  6. $ip = $_SERVER["REMOTE_ADDR"];
  7. for ($i=0; $i < $ile; $i++) {
  8. $pol = explode("`",$bazaip[$i]);
  9. if ($pol[2] < time()) {$bazaip[$i]= "";}
  10. if ($pol[1]==$ip) {
  11. $bazaip[$i]="`$ip`$czas`\n"; $jest=1;
  12. }
  13. }
  14. if ($jest<>1) $bazaip[]="`$ip`$czas`\n";
  15. $f = fopen("online.txt","w");flock($f,2);
  16. for ($i=0; $i < $ile+1; $i++) {
  17. if ($bazaip[$i]<>"") { fwrite($f, $bazaip[$i]); $ileip++;}
  18. }
  19. flock($f,3); fclose($f);
  20. echo "Osób on-line: <b>".$ileip."</b>";
  21. ?>


Tu musisz stworzyc plik online.txt i nadac mu chmod 666
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.