#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    7
    Rep Power
    0

    Talking recording number of clicks


    I would like to record how many times peopple click this one link i have on my website is there a php script that does that or some sort of cgi script?
  2. #2
  3. Moderator Emeritus
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2002
    Location
    Austin, TX
    Posts
    7,186
    Rep Power
    2265
    Moved from PHP forum to Scripts forum
    DrGroove, Devshed Moderator | New to Devshed? Read the User Guide | Connect with me on LinkedIn
  4. #3
  5. Moderator Emeritus
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2002
    Location
    Austin, TX
    Posts
    7,186
    Rep Power
    2265
    Did you check Hotscripts, Sourceforge, Google... ?
    DrGroove, Devshed Moderator | New to Devshed? Read the User Guide | Connect with me on LinkedIn
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    London, England
    Posts
    279
    Rep Power
    12

    Re: recording number of clicks


    Originally posted by amorpheus
    I would like to record how many times peopple click this one link i have on my website is there a php script that does that or some sort of cgi script?
    Do you still need help?

    If it's just one link, you could change it to redirect to (for instance) 'hit.php'.
    You would need to have a 'hits.txt' file with 666 access (CHMOD 666 hits.txt)

    hit.php:
    Code:
    <?php
    ## Open hits counter to get current count ##
    $fH = @fopen('hits.txt', 'r');
    
    ## Only save new count if it opened ##
    if ($fH)
    {
        $count = fgets($fH, 1024);
        @fclose($fH);
    
        ## Add one to count (or restart if corrupt) ##
        if (is_numeric($count))
            $count++;
        else
            $count = 1;
    
        ## Only save if possible ##
        $fH = @fopen('hits.txt', 'w');
        if ($fH)
            fputs($count . "\n");
        @fclose($fH);
    }
    
    ## Redirect ##
    header('Location: http://new/url/');
    ?>
    Of course, if you're talking about many links, I'd suggest using a database back-end.

    Hope this helps
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    7
    Rep Power
    0
    hmm thanx...what does the txt file suposed to look like?
    i tested the link out but it doesnt record it to txt...and im running my own apache webserver on windows so..chmod i dont think is available so how do i deal with that?
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    London, England
    Posts
    279
    Rep Power
    12
    As far as I know, you shouldn't have any problems with write properties on windows.

    The text file should create itself. If not, try creating a blank hits.txt (or whatever).
    It's possible Apache isn't letting you create new files.

    If you take the '@' symbols off while debugging, it should give you some extra info.
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    7
    Rep Power
    0
    it doesnt log anything to hit.txt....
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    London, England
    Posts
    279
    Rep Power
    12
    Have you tried removing the '@' symbols to see if any errors are produced?

    It should tell you if the file cannot be read or written to, for any reason.
  16. #9
  17. No Profile Picture
    Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Chandigarh, India
    Posts
    33
    Rep Power
    0
    Lot of click tracking scrupts out there !!at hotscripts !!
  18. #10
  19. No Profile Picture
    // banan2 PRIDE //
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Norway
    Posts
    303
    Rep Power
    12

    Re: Re: recording number of clicks


    Originally posted by Wite_Noiz
    Do you still need help?

    If it's just one link, you could change it to redirect to (for instance) 'hit.php'.
    You would need to have a 'hits.txt' file with 666 access (CHMOD 666 hits.txt)

    hit.php:
    Code:
    <?php
    ## Open hits counter to get current count ##
    $fH = @fopen('hits.txt', 'r');
    
    ## Only save new count if it opened ##
    if ($fH)
    {
        $count = fgets($fH, 1024);
        @fclose($fH);
    
        ## Add one to count (or restart if corrupt) ##
        if (is_numeric($count))
            $count++;
        else
            $count = 1;
    
        ## Only save if possible ##
        $fH = @fopen('hits.txt', 'w');
        if ($fH)
            fputs($count . "\n");
        @fclose($fH);
    }
    
    ## Redirect ##
    header('Location: http://new/url/');
    ?>
    Of course, if you're talking about many links, I'd suggest using a database back-end.

    Hope this helps
    Didnt work..

    Error:
    Warning: Wrong parameter count for fputs() in /mnt/home3/b/ba/banan289/public_html/m-eye/gbcount.php on line 20

    Warning: Cannot add header information - headers already sent by (output started at /mnt/home3/b/ba/banan289/public_html/m-eye/gbcount.php:20) in /mnt/home3/b/ba/banan289/public_html/m-eye/gbcount.php on line 25

IMN logo majestic logo threadwatch logo seochat tools logo