Guest User

Untitled

a guest
Feb 25th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. <?php
  2.  
  3. require_once('conn.php');
  4.  
  5. $time = 5 ;
  6.  
  7. $date = time() ;
  8.  
  9. $ip = $_SERVER['REMOTE_ADDR'];
  10.  
  11. $limite = $date-$time*60 ;
  12.  
  13. mysql_query("delete from online where date < $limite") ;
  14.  
  15. $resp = mysql_query("select * from online where ip='$ip'") ;
  16.  
  17. if(mysql_num_rows($resp) != 0) {
  18. mysql_query("update online set date='$date' where ip='$ip'") ;
  19. }
  20.  
  21. else {
  22. mysql_query("insert into online (date,ip) values ('$date','$ip')") ;
  23. }
  24.  
  25. $query = "SELECT * FROM online";
  26.  
  27. $resp = @mysql_query($query) or die(mysql_error());
  28.  
  29. $usuarios = mysql_num_rows($resp);
  30.  
  31. if($usuarios > 1 || $usuarios == 0){
  32. echo("Hay ");
  33. }else{
  34. echo("Hay ");
  35. }if($usuarios == 0){
  36. echo("no ");
  37. }else{
  38. echo($usuarios." ");
  39. }if($usuarios > 1 || $usuarios == 0){
  40. echo("Usuarios en línea.");
  41. }else{echo("usuario en línea.");
  42. }?>
  43.  
  44. <?php
  45.  
  46. include('conn.php');
  47.  
  48.  
  49. $ip = $_SERVER['REMOTE_ADDR'];
  50.  
  51.  
  52.  
  53. $sql="select ip, TIMEDIFF(NOW(), fecha), fecha, num_visitas from visitas where ip='$ip'";
  54.  
  55.  
  56.  
  57. $rs=mysql_query($sql) or die("Problemas al ejecutar select SQL ".mysql_error());
  58.  
  59.  
  60.  
  61. $fila=mysql_fetch_array($rs);
  62.  
  63. $tiempo=$fila[1];
  64.  
  65. $num_visitas=$fila[3];
  66.  
  67. $horas_t=substr($tiempo,0,2);
  68.  
  69. $tiemRes = 5;
  70.  
  71. if (mysql_num_rows($rs)==0)
  72.  
  73. {
  74.  
  75. $sql="insert into visitas(ip, num_visitas, fecha) values('$ip', 1, NOW())";
  76.  
  77. mysql_query($sql) or die("Problemas al ejecutar la insert SQL ".mysql_error());
  78.  
  79. }
  80.  
  81.  
  82.  
  83. elseif (mysql_num_rows($rs) > 0 && $horas_t > $tiemRes)
  84.  
  85. {
  86.  
  87. $sql="update visitas set fecha=NOW(), num_visitas='$num_visitas'+1 where ip='$ip'";
  88.  
  89. mysql_query($sql) or die("Problemas al ejecutar update SQL ".mysql_error());
  90.  
  91. }
  92.  
  93. $sql="select SUM(num_visitas) from visitas";
  94.  
  95. $rs=mysql_query($sql) or die("Problemas al ejecutar select SQL ".mysql_error());
  96.  
  97. $fila=mysql_fetch_array($rs);
  98.  
  99. $num_visitas=$fila[0];
  100.  
  101. mysql_close($conection); ?>
Add Comment
Please, Sign In to add comment