Results 1 to 8 of 8

Thread: How can I monitor what links my surfers are clicking

  1. #1
    Join Date
    Jul 2005
    Posts
    101
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default How can I monitor what links my surfers are clicking

    My site is a directory showing business contact details including web links.

    Each link is displayed within <td></td> tags and target is _blank.

    I would like to know what external links users may be clicking on.

    Is there any way to store what they've clicked on e.g. the href and date, to a simple text file on my site?
    Cheers
    Billy

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Yes. You need a "redirect" page, which should be invisible to the user.
    PHP Code:
    // redir.php
    $log fopen("/ws.log""a");
    fputs($_SERVER['HTTP_REMOTE_ADDR'] . ' accessed ' $_GET['url'] . ' on ' date("g:i, D") . ' the ' .date("dS") . ' of ' date("F") . ' from ' $_SERVER['HTTP_REFERER'] . "\n"$log);
    fclose($log);
    header("Location: http://www.mysite.com/" $_GET['url']); 
    Link to it like so: redir.php?url=pages%2fpagetogoto.htm to go to http://www.mysite.com/pages/pagetogoto.htm.
    %2f, by the way, is URL-talk for '/'.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jul 2005
    Posts
    101
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    Thanks Twey.

    I'm afraid I'm not too clear on the use of this.

    If the link on mysite.com reads:

    <a href="theirsite.com" target=_blank>See their site</a>

    I should change this to:

    <a href ="redir.php?url=theirsite.com" target=_blank>See their site</a>

    and in redir.php I should use header ("Location: $_GET['url']")
    to go on to theirsite.com
    Cheers
    Billy

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Ah, yes, sorry. I was thinking only in terms of pages on your site. What you suggest will indeed work.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Jul 2005
    Posts
    101
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    Brilliant! Thanks again, Twey
    Cheers
    Billy

  6. #6
    Join Date
    Jul 2005
    Posts
    101
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    I've uploaded amended pages and now call the script ok.
    I had to change it slightly to get it to work (by putting the log filename as the first parameter).

    My version is

    <?php
    $log = fopen("ws.log", "a");
    fputs($log,$_SERVER['HTTP_REMOTE_ADDR'] . ' accessed ' . $_GET['url'] . ' on ' . date("g:i, D") . ' the ' .date("dS") . ' of ' . date("F") . ' from ' . $_SERVER['HTTP_REFERER'] . "\n" );
    fclose($log);
    Header ("Location: " . $_GET['url']);
    ?>

    However, the remote_addr is not being written to the log. This is a line from the log:
    accessed http://www.eurobrokers.org on 12:15, Sat the 15th of October from http://www.estateagentsespana.com/co..._agents_01.htm

    Any idead why?
    Cheers
    Billy

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I beg your pardon, it's not HTTP_REMOTE_ADDR, just REMOTE_ADDR.
    I've made far too many errors on this thread. Time to brush up my PHP again
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Jul 2005
    Posts
    101
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    As ever, your help is greatly appreciated, Twey.

    As for errors, once we get there in the end do they matter?
    Cheers
    Billy

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •