Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. <?php
  2. //conectare
  3. $servername = "localhost";
  4. $username = "root";
  5. $password = "";
  6. $dbname = "esticuri_utile";
  7.  
  8. //create connection to mysql
  9. $db_conx_count = mysqli_connect($servername, $username, $password, $dbname);
  10. $db_conx_count->set_charset('utf8');// pentru diacritice
  11. if(!$db_conx_count){
  12. die("Connection failed: ". mysqli_connect_error());
  13. }
  14.  
  15. // gets the user IP Address
  16. $user_ip = $_SERVER['REMOTE_ADDR'];
  17. $pagenew = $_SERVER['REQUEST_URI'];
  18.  
  19. $check_ip = "select userip from pageview where page='$pagenew' and userip='$user_ip'";
  20. $query1 = mysqli_query($db_conx_count, $check_ip);
  21. if (!$check_ip || mysqli_num_rows($check_ip) >= 1)
  22. {
  23.  
  24. }
  25. else
  26. {
  27. $insertview = "insert into pageview values('','$pagenew','$user_ip')";
  28. $query2 = mysqli_query($db_conx_count, $insertview);
  29. $updateview = "update totalview set totalvisit=totalvisit + 1 where page='$pagenew' ";
  30. $query3 = mysqli_query($db_conx_count, $updateview);
  31. }
  32. ?>
  33.  
  34. <html>
  35. <head>
  36. </head>
  37.  
  38. <body>
  39. <?php
  40. $stmt = "select totalvisit from totalview where page='$pagenew' ";
  41. $query_stmt = mysqli_query($db_conx_count, $stmt);
  42. ?>
  43.  
  44. <p>This page is viewed <?php echo mysqli_num_rows($query_stmt);?> times.</p>
  45. <?php mysqli_close($db_conx_count);?>
  46. </body>
  47. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement