Full Counter

 <?php  

error_reporting(0);

include 'config.php';

$page_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";




//retrive all data from database

$sql = "SELECT * FROM visitors3";

$result = mysqli_query($conn,$sql);


//check retriving data ok or not

if (!$result) {

die("Retriving Data Error".$sql);

}


//count total visitors

$total_visitors = mysqli_num_rows($result);

echo "Total Visitors - ".$total_visitors."<br>";


//get visitors IP

$user_ip = "f7gf";

//$user_ip = $_SERVER['REMOTE_ADDR'];

//echo "User IP - ".$user_ip;


//check user ip exsit or not

$sql = "SELECT * FROM visitors3 WHERE user_ip = '$user_ip'";

$result = mysqli_query($conn,$sql);

$check_ip = mysqli_num_rows($result);


if ($check_ip<1) {

$sql = "INSERT INTO visitors3(user_ip,page_url) VALUES ('$user_ip','$page_url')";

$result = mysqli_query($conn,$sql);


}



//count unique ip


$sql = "SELECT COUNT(DISTINCT user_ip) as totalcount FROM visitors3";

$result = mysqli_query($conn,$sql);

while($row = mysqli_fetch_array($result))

{

    echo "Total Unique Visitors - ".$row['totalcount']."<br>";

}





 //update ip wise page

$sql = "SELECT page_url FROM visitors3 WHERE page_url = '$page_url' AND user_ip = '$user_ip' ";

$result = mysqli_query($conn, $sql);

$row = mysqli_fetch_array($result);


$check_url = mysqli_num_rows($result);


if ($check_url<1)

   {

    $sql = "INSERT INTO visitors3(user_ip,page_url) VALUES ('$user_ip','$page_url')";

$result = mysqli_query($conn,$sql);


   }

 else

    {

   //echo"This url is exist";

    }



//update data by visitor visting page

    $sql = "UPDATE visitors3 SET total_visit = total_visit+1 WHERE page_url ='$page_url'";

    $conn->query($sql);


    //fetch total number of last page views 

    $sql = "SELECT total_visit FROM visitors3 WHERE page_url ='$page_url' ";

    $result = $conn->query($sql);

    if ($result->num_rows > 0) {

        while($row = $result->fetch_assoc()) {

            $total_visit = $row["total_visit"];

            $tools_views = $total_visit." Views";

        }

    } else {

    echo "0 Views";

    }

    echo $tools_views;


?>

Post a Comment

0 Comments