Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.89 KB | None | 0 0
  1. <?php
  2.  
  3. // Replace with your information
  4. $host = "localhost";
  5. $username = "root";
  6. $password = "";
  7. $dbname = "test";
  8.  
  9. // Counter initialization
  10. $count = 0;
  11.  
  12. // Connect to the database
  13. $dblink = mysql_connect($host, $username, $password);
  14. if($dblink) {
  15.   mysql_select_db($dbname, $dblink) or die("Cannot connect to the database"); // note that passing $dblink is not necessary
  16.  
  17.   // Insert the new count
  18.   mysql_query("INSERT INTO `counter` (`remote_addr`, `page_url`, `date_time`) VALUES ('".mysql_real_escape_string($_SERVER['REMOTE_ADDR'])."', '".mysql_real_escape_string($_SERVER['REQUEST_URI'])."', NOW())");
  19.  
  20.  
  21.   // Select the site pages count
  22.   $rs = mysql_query("SELECT COUNT(*) AS `count` FROM `counter`");
  23.   if($rs !== false && mysql_num_rows($rs) == 1)
  24.   {
  25.     $assoc = mysql_fetch_assoc($rs);
  26.     $count = $assoc['count'];
  27.   }
  28.  
  29.   // Display the count
  30.   echo $count;
  31. }
  32. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement