Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Replace with your information
- $host = "localhost";
- $username = "root";
- $password = "";
- $dbname = "test";
- // Counter initialization
- $count = 0;
- // Connect to the database
- $dblink = mysql_connect($host, $username, $password);
- if($dblink) {
- mysql_select_db($dbname, $dblink) or die("Cannot connect to the database"); // note that passing $dblink is not necessary
- // Insert the new count
- 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())");
- // Select the site pages count
- $rs = mysql_query("SELECT COUNT(*) AS `count` FROM `counter`");
- if($rs !== false && mysql_num_rows($rs) == 1)
- {
- $assoc = mysql_fetch_assoc($rs);
- $count = $assoc['count'];
- }
- // Display the count
- echo $count;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement