phpuniquevisitors

Simple way to check non logged visitors uniqueness


Is there any way of knowing, when a user comes to my website, if he has already come, without having users to login ? I do not need it to be extremely accurate, but to be simple to implement and to work in most cases. I thought of using a ip address+useragent combo. What do you think about it ?


Solution

  • Set a cookie on every user's visit on your site, If the client has that cookie it means he has already visited your site else he has'nt or it could be also checked by IP

    A quick script using Cookies:

    if(isset($_COOKIE["user_visited"]))
    {
        //He has already visited you.
    }else{
        //Set a new cookie.
        setcookie("user_visited","user");
    }
    

    IP Method

    //Need to create a user_ip table for it and store everybodies ip(s) in it.
    $user_ip    =   $_SERVER["REMOTE_ADDR"];
    if(isset($user_ip)){
        $query  =   mysql_query("SELECT * FROM `user_ip` WHERE `ip`='$user_ip'");
        $count  =   mysql_num_rows($query);
        if($count > 0){
            //User already visited you
        }else{
            //He hasn't visited you.
            //Save his IP to know if he visit again.
            $query("INSERT INTO `user_ip` VALUES('$user_ip')");
        }
    }