1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Unique hit and visitor counter

Discussion in 'PHP' started by Hannaspice, Sep 12, 2012.

  1. #1
    Hi everybody,
    I need a hit counter, which could count unique visitors per page. Now i have this one:

    $link_id = $_GET['ico'];
    	$sql = "UPDATE `quicklink` SET `views`=views+1 WHERE `id`=" . $link_id;
    	$result = mysql_query($sql);
    
    PHP:
    The problem with this is it increase the count if you refresh the page even though it's been visited. How can I stopped the count if it's been visited or one ip= 1 view only?

    I donnot want to save all visits to my database like:

    $ip = $_SERVER['REMOTE_ADDR']; 
    $location = $_SERVER['PHP_SELF']; 
    PHP:
    I think saving all them to the database is not a good solution. I just want to count visitor ip for each article. Any help?
     
    Hannaspice, Sep 12, 2012 IP
  2. Arttu

    Arttu Member

    Messages:
    139
    Likes Received:
    2
    Best Answers:
    8
    Trophy Points:
    40
    #2
    Check if user's ip is already in the db
    Yes
         Do nothing
    No
         Add users ip in the db
         Increase the visitor count by 1
    Code (markup):
     
    Arttu, Sep 13, 2012 IP
  3. shiva.veepuri

    shiva.veepuri Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You must need store IP, as well as ID of article,

    You have to check both, if record not exists then update both tables.
     
    shiva.veepuri, Sep 13, 2012 IP
  4. ezprint2008

    ezprint2008 Well-Known Member

    Messages:
    611
    Likes Received:
    15
    Best Answers:
    2
    Trophy Points:
    140
    Digital Goods:
    1
    #4
    get the IP $ip = $_SERVER['REMOTE_ADDR'];
    and create a text file with fwrite ()

    then a simple script for
    if file_exists($uniqueIP _127.0.00 (users IP) {
    do nothing
    }
    else {

    write the IP to a text file of $uniqueIP_ (users IP)


    have the program create a folder (make directory) with todays date, that way it can delete the directory /folder the next day and create a new
    if directory exists , do nothing, if directory doesn't exist, create it of 09/13/2012

    That way you will have only txt files that are named after their IP and on next day if the scripts sees an old folder, it will check database to see if the files had been entered, if not it will enter the IP inside of every file to the database. otherwise it deletes it.

    Another way is to write to a file and append new IPs to the file only if the script reads the file and finds no stringmatch.

    Either way, you could create an interface to check the text files in a folder or the lines of appended code of IPs to see at a glance through your interface how many unique IP visits that day.
     
    ezprint2008, Sep 13, 2012 IP