Alice AUSTIN

Alice AUSTIN is studying Cisco Systems Engineering. He has passion with both hardware and software and writes articles and reviews for many IT websites.

23 thoughts on “PHP: Simple visitor counter by IP address

  • if i use the real web server with this code, will they update the database? or the database only for the localhost?

  • Hi bro…I want to Post articles to Facebook from my website using PHP and MySQL ….plz can u help me ?…

  • Hi bro…I want to Post articles to Facebook from my website using PHP and MySQL ….plz can u help me ?…

  • Sir, is it possible to show IP on the visitor's site?
    I mean, user can see the own IP.

  • Showing me This Error:
    Parse error: syntax error, unexpected 'ip' (T_STRING) in C:wamp64wwwtestindex.php on line 18

    * Code I Use Same

    1 <?php

    2 // connection with database

    3 $host='localhost';

    4 $user='root';

    5 $pass='';

    6 $db='test';

    7 try{

    8 $DBH=new pdo("mysql:host=$host;dbname=$db",$user,$pass);

    9 }catch(PDOException $e){

    echo"Not connected..".$e->getMessage();

    10 }

    11 // Get Ip

    12 $ip = $_SERVER['REMOTE_ADDR'];

    13 // Check if this ip exist in out data

    14 $sql="SELECT ip FROM visitors WHERE ip=$ip";

    15 $check=$DBH->prepare($sql);

    16 $check->execute();

    17 $checkIp=$check->rowCount();

    18 if($checkIp==0) {

    19 $query="INSERT INTO visitors(id,ip) VALUES(NULL,'$ip')";

    20 $inserIp=$DBH->prepare($query);

    21 $insertIp->execute();

    22 }

    23 $number=$DBH->prepare("SELECT ip FROM visitors");

    24 $number->execute();

    25 $visitor=$number->rowCount();

    26 echo $visitor;

    27?>

  • Hi, I write the code like in the video but the result is zero.Why? How to make it functional?Thank you

  • its Unique Visitor County without any timeline (life time).
    its don't count how many visit happen by per IP.

Comments are closed.