Pomoc - Szukaj - U¿ytkownicy - Kalendarz
Pe³na wersja: [php/mysql] Goscie Online
Forum PHP.pl > Forum > PHP
zaba12
Witam mam problem jak zrobic zeby usuwa³ mi wpis jak gosc wyjdzie ze strony lub zamknie przegladarke bo mam takie cos ale cos mi nie dzia³a tyle tylko napisa³em ;/ Proszê o pomoc.

  1. <?php
  2. $ip=$_SERVER["REMOTE_ADDR"];
  3.  
  4. $resultu = mysql_query("SELECT * FROM `users_guest` WHERE ip='$ip'") or die(mysql_error());
  5. $resultuz = mysql_query("SELECT * FROM `users_guest`") or die(mysql_error());
  6. $row = mysql_fetch_array($resultu);
  7. if (mysql_num_rows($resultu)==0){
  8.  mysql_query("INSERT INTO users_guest VALUES ('', NOW(), '$ip')") or die(mysql_error());
  9. } else {
  10.  mysql_query ("UPDATE users_guest SET timeu=NOW() WHERE ip='$ip'") or die(mysql_error());
  11. }
  12. $ileu = mysql_num_rows($resultuz);
  13.  
  14. echo '<br>Gosci: '.$ileu;
  15. $time=time();
  16. $minutes=5*60;
  17. $time_offline=(time()-$minutes);
  18. mysql_query("DELETE FROM users_guest WHERE timeu=NOW()");
  19. ?>
zaba12
¿al ja niechce na plikach .... tylko na mysql chce zrobic exclamation.gif! i po co mi linki prowadzace do tekstowych statystyk gosci online
jang
Ludzie, Wam naprawdê nie warto czegokolwiek podpowiedzieæ. Jeste¶cie takimi ¶mierdz±cymi leniami ¿e a¿ w d....e ¶ciska, nie chce siê Wam nawet zagl±dn±æ tylko od z góry wiecie ¿e to nie to

Da³em Ci link i tu masz kod :

  1. <?
  2. /*
  3. ************************************************************************
  4. * � Sloppycode.net All rights reserved.
  5. *
  6. * This is a standard copyright header for all source code appearing
  7. * at sloppycode.net. This application/class/script may be redistributed,
  8. * as long as the above copyright remains intact. 
  9. * Comments to sloppycode@sloppycode.net
  10. ************************************************************************
  11. */
  12.  
  13. /*
  14. * @title OnlineUsers Class, incorporating DataProducer class
  15. * @author C.Small
  16. * @version 2.1 - Public property for frequency of row deletion
  17. * @version 2.0 - Database optimisation - change in table structure
  18. * @version 1.0 - From an original written by Genesis <freedomfighter2015@home.com>
  19. */
  20. class DataProducer
  21. {
  22.  
  23. function doDataProducer($startTag,$endTag,$data,$contents)
  24. {
  25. return $this->privateDataProducer($startTag,$endTag,$data,$contents);
  26. }
  27. function doSingleDataProducer($data,$contents)
  28. {
  29. return $this->privateSingleDataProducer($data,$contents);
  30. }
  31. function openTemplate($filename)
  32. {
  33. return $this->privateopenTemplate($filename);
  34. }
  35.  
  36. function privateDataProducer($startTag,$endTag,$data,$contents)
  37. {
  38. // Get start and end points
  39. $start = strpos($contents,$startTag);
  40. $end  = strpos($contents,$endTag,$startTag);
  41.  
  42. // Retrieve everything before start tag
  43. $prefix = substr($contents,0,$start);
  44. $prefix = rtrim($prefix);
  45.  
  46. // Retrieve everything after end tag. Make it starts at the end of end-tag
  47. $suffix = substr($contents,$end + strlen($endTag),strlen($contents) - ($end + strlen($endTag)));
  48. $suffix = ltrim($suffix);
  49.  
  50. // Retrieve data template. make sure it starts at the end of the start-tag.
  51. $dataTemplate = substr($contents,$start + strlen($startTag),$end - ($start + strlen($startTag)));
  52.  
  53. // New method implemented here
  54. for ($i=0; $i <= sizeof($data) -1;$i++)
  55. {
  56. $tempReplace = $dataTemplate;
  57. $tempReplace = rtrim($tempReplace);
  58.  
  59. $keys = array_keys($data[$i]);
  60. foreach($keys as $keyname)
  61. {
  62. if (!empty($data[$i][$keyname]))
  63. {
  64. $tempReplace = str_replace("<".$keyname.">",$data[$i][$keyname],$tempReplace);
  65. } else{
  66. $tempReplace = str_replace("<".$keyname.">","",$tempReplace);
  67. }
  68. }
  69. $build .= $tempReplace;
  70. }
  71.  
  72. return $prefix . $build . $suffix;
  73. }
  74. /**
  75.  *
  76.  */
  77. function privateSingleDataProducer($data,$contents)
  78. {
  79. $result = $contents;
  80. foreach ($data as $tagname => $value){
  81. $result = str_replace("<".$tagname.">",$value,$result);
  82. }
  83. return $result;
  84. }
  85. /**
  86.  *
  87.  */
  88. function privateOpenTemplate($filename)
  89. {
  90. $fHnd = @fopen($filename,"r") or die("<br><b>Unable to open template: ".$filename."</b>");
  91. $contents = @fread($fHnd,filesize($filename)) or die("<br><b>Unable to open template: ".$filename."</b>");
  92. fclose($fHnd);
  93.  
  94. return $contents;
  95. }
  96. }
  97.  
  98. Class OnlineUsers Extends DataProducer
  99. {
  100. // Public
  101. var $host;
  102. var $username;
  103. var $password;
  104. var $dbname;
  105. var $tablename;
  106. var $timeout;
  107. var $update_frequency = 5;
  108.  
  109. // Private
  110. var $conn;
  111. var $db;
  112. var $totalusers;
  113.  
  114. function dbconnect()
  115. {
  116. $this->conn  = mysql_connect($this->host,$this->username,$this->password);
  117. }
  118.  
  119. function setup($createdb)
  120. {
  121. // Create database if specified
  122. if ($createdb)
  123. {
  124. $SQL = "CREATE DATABASE IF NOT EXISTS ".$this->dbname;
  125. $result = mysql_query($SQL);
  126. }
  127.  
  128. // Connect to specified db + drop table if it exists
  129. $this->db = mysql_select_db($this->dbname,$this->conn);
  130. $SQL = "DROP TABLE IF EXISTS ".$this->tablename;
  131. $result = mysql_query($SQL);
  132.  
  133. // Create table with tablename
  134. $SQL = "CREATE TABLE ".$this->tablename." (
  135. ip varchar(15) NOT NULL DEFAULT '' ,
  136. time int(11) ,
  137. PRIMARY KEY (ip),
  138. UNIQUE id (ip),
  139. INDEX id_2 (ip)
  140. );";
  141. $result = mysql_query($SQL);
  142. }
  143.  
  144. function updateAddUser()
  145. {
  146. global $HTTP_COOKIE_VARS;
  147.  
  148. $this->db = mysql_select_db($this->dbname,$this->conn);
  149.  
  150. $current_seconds = date(U);
  151. $deadline_seconds = $current_seconds - ($this->timeout * 60);
  152. $timeout_seconds = $this->timeout * 60;
  153.  
  154. // Delete users that aren't connected anymore, according to $timeout;
  155. // (v2) No need to do it everytime - reduces load on heavily hit servers
  156. // this does it every 1 in 10 times
  157. mt_srand((double)microtime() * 1000000);
  158. if (mt_rand(0, $this->update_frequency) == 1)
  159. {
  160. $SQL = "DELETE FROM ".$this->tablename." WHERE time between 0 AND ".$deadline_seconds;
  161. $result = mysql_query($SQL);
  162. }
  163.  
  164. $user_ip = getenv("REMOTE_ADDR");
  165.  
  166. $SQL = "REPLACE INTO ".$this->tablename." (ip,time) VALUES ('".$user_ip."','".$current_seconds."')";
  167. $result = mysql_query($SQL);
  168. }
  169.  
  170. function showFullInfo($lookuphosts,$contents)
  171. {
  172. $this->db = mysql_select_db($this->dbname,$this->conn);
  173. $current_seconds = date(U);
  174.  
  175. $this->getUsersOnline();
  176. $tags['totalusers'] = $this->totalusers;
  177. $tags['timeout_seconds'] = $this->timeout * 60;
  178. $tags['timeout_minutes'] = $this->timeout;
  179. $contents = $this->doSingleDataProducer($tags,$contents);
  180. unset($tags);
  181.  
  182. $SQL = "SELECT ip,time FROM ".$this->tablename;
  183. $result = mysql_query($SQL);
  184. while ($RS = mysql_fetch_array($result))
  185. {
  186. // Check it's not immediate
  187. if (($current_seconds - $RS[1]) <1)
  188. {
  189. $tags['seconds_ago'] = " 0";
  190. } else{
  191. $tags['seconds_ago'] = $current_seconds - $RS[1];
  192. }
  193.  
  194. $tags['ipaddress']  = $RS[0];
  195.  
  196. // Lookup IP host name if specified
  197. if ($lookuphosts)
  198. {
  199. $tags['host'] = gethostbyaddr($RS[0]);
  200. }
  201. $rows[] = $tags;
  202. unset($tags);
  203. }
  204. $contents = $this->doDataProducer("<user_details>","</user_details>",$rows,$contents);
  205. return $contents;
  206. }
  207.  
  208. function getUsersOnline()
  209. {
  210. $this->db = mysql_select_db($this->dbname,$this->conn);
  211.  
  212. // Get number of users online
  213. $SQL = "SELECT count(ip) FROM ".$this->tablename;
  214. $result = mysql_query($SQL);
  215. $RS = mysql_fetch_row($result);
  216. $this->totalusers = $RS[0];
  217. return $RS[0];
  218. }
  219. }
  220. ?>


To jest plik tekstowy questionmark.gifquestionmark.gifquestionmark.gifquestionmark.gifquestionmark.gifquestionmark.gifquestionmark.gif
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.