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.

Make this record unique hits aswell.

Discussion in 'PHP' started by Sphinx1994, Aug 25, 2010.

  1. #1
    I currently have it like this:

    <?php
    $filename = "hits.txt";
    
    $file = file($filename);
    $file = array_unique($file);
    $hits = count($file);
    echo $hits;
    echo "$refer"; 
    $fd = fopen ($filename , "r");
    $fstring = fread ($fd , filesize ($filename));
    fclose($fd);
    $fd = fopen ($filename , "w");
    $fcounted = $fstring."IP: ".getenv("REMOTE_ADDR");
    $refer = ' Referrer: ' . $_SERVER["HTTP_REFERER"] . "\n";
    $fout= fwrite ($fd , $fcounted . $refer);
    fclose($fd);
    ?>
    PHP:
    When i go on it twice from my pc, this is exactly what it shows on the txt file:
    IP: 78.148.52.111 Referrer: youtube.com etc whereever user clicked. 
    IP: 78.148.52.111 Referrer: youtube.com etc whereever user clicked.
    Code (markup):
    I basicly want it to do this:

    Unique hits: 43
    IP: 78.148.52.111 Referrer: youtube.com etc where-ever user clicked. 
    IP: 78.148.52.111 Referrer: youtube.com etc where-ever user clicked.
    Code (markup):
    Etc, thanks.
     
    Sphinx1994, Aug 25, 2010 IP
  2. learnerabn

    learnerabn Peon

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think the problem here is,you have opened the file in write mode
    and written only the IP address and HTTP_REFERER.
    so it would display it only.
    if you want to display the hits you have to write it also in the file.
    Or if you want to uppend the file then you have to open it in w+ mode.
     
    learnerabn, Aug 25, 2010 IP