Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Licznik osób online
radmistrz2
post 10.07.2008, 10:59:26
Post #1





Grupa: Zarejestrowani
Postów: 143
Pomógł: 4
Dołączył: 2.03.2008

Ostrzeżenie: (10%)
X----


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??
Go to the top of the page
+Quote Post
_olo_1984
post 10.07.2008, 11:20:30
Post #2





Grupa: Zarejestrowani
Postów: 289
Pomógł: 77
Dołączył: 5.08.2006

Ostrzeżenie: (0%)
-----


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


--------------------
awake
Go to the top of the page
+Quote Post
radmistrz2
post 10.07.2008, 11:57:49
Post #3





Grupa: Zarejestrowani
Postów: 143
Pomógł: 4
Dołączył: 2.03.2008

Ostrzeżenie: (10%)
X----


nie działa
Go to the top of the page
+Quote Post
_olo_1984
post 10.07.2008, 12:52:12
Post #4





Grupa: Zarejestrowani
Postów: 289
Pomógł: 77
Dołączył: 5.08.2006

Ostrzeżenie: (0%)
-----


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.


--------------------
awake
Go to the top of the page
+Quote Post
radmistrz2
post 10.07.2008, 15:06:34
Post #5





Grupa: Zarejestrowani
Postów: 143
Pomógł: 4
Dołączył: 2.03.2008

Ostrzeżenie: (10%)
X----


Parse error: syntax error, unexpected T_STATIC, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in
Go to the top of the page
+Quote Post
mike
post 10.07.2008, 15:07:29
Post #6





Grupa: Przyjaciele php.pl
Postów: 7 494
Pomógł: 302
Dołączył: 31.03.2004

Ostrzeżenie: (0%)
-----


Masz PHP4 a podany kod jest na PHP5.
Zainstaluj PHP5 i nie baw się w archeologię tongue.gif
Go to the top of the page
+Quote Post
Puzi
post 10.07.2008, 15:15:16
Post #7





Grupa: Zarejestrowani
Postów: 231
Pomógł: 17
Dołączył: 26.08.2007

Ostrzeżenie: (10%)
X----


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

Ten post edytował Puzi 10.07.2008, 15:17:51
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 18.07.2025 - 00:32