in

PHP Live Online Viewers Counter, Total Pageview Counter, Track Website Hits

PHP Live Online Viewers Counter, Total Pageview Counter, Track Website Hits

PHP Live Online Viewers Counter, Total Pageview Counter, Track Website Hits

 

To create a PageView Counter System we have to Make a PHP file and define codes for PageView Counter System and Display Total Page Views.

We make a PHP file and save it with a name pageview.php

We have to get User IP Address to make PageView Counter System so that our PageView counter increments the total visit with the visit of every unique user and every unique user means every unique IP Address.You may also like date time countdown timer using JavaScript.

 

We have to make two database table One is for storing the webpage name and IP Address and second one is for updating the total visits every time a unique visitor visit our respective webpage.

Database:
// pageview

CREATE TABLE `pageview` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`page` text NOT NULL,
`userip` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1

// totalview

CREATE TABLE `totalview` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`page` text NOT NULL,
`totalvisit` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1

pageview.php
<?php
$host=”localhost”;
$username=”root”;
$password=””;
$databasename=”sample”;

$connect=mysql_connect($host,$username,$password);
$db=mysql_select_db($databasename);

// gets the user IP Address
$user_ip=$_SERVER[‘REMOTE_ADDR’];

$check_ip = mysql_query(“select userip from pageview where page=’yourpage’ and userip=’$user_ip'”);
if(mysql_num_rows($check_ip)>=1)
{

}
else
{
$insertview = mysql_query(“insert into pageview values(”,’yourpage’,’$user_ip’)”);
$updateview = mysql_query(“update totalview set totalvisit = totalvisit+1 where page=’yourpage’ “);
}
?>

Written by YT Solution

What do you think?

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Loading…

0
Transparent Login and Signup Form Using HTML CSS

Transparent Login and Signup Form Using HTML CSS

Mouse Hover Zoom Effect

Mouse Hover Zoom Effect Using Css, Mouse Hover Transition Effect