View Full Version : How can I monitor what links my surfers are clicking
10-06-2005, 07:00 PM
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?
Yes. You need a "redirect" page, which should be invisible to the user.
$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);
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 '/'.
10-06-2005, 11:22 PM
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
Ah, yes, sorry. I was thinking only in terms of pages on your site. What you suggest will indeed work.
10-07-2005, 09:44 AM
Brilliant! Thanks again, Twey
10-18-2005, 04:41 PM
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
$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" );
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/costadelsol/benalmadena_estate_agents_01.htm
Any idead why?
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 :p
10-18-2005, 06:09 PM
As ever, your help is greatly appreciated, Twey.
As for errors, once we get there in the end do they matter? :p
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.