Forum Moderators: open
I've finally come up with a solution to count my outbound clicks without using another file to forward. I wanted to post it here before I went live with it to see if anyone had any suggestions for improvement. I just needed a way to count the clicks while still retaining the original URL so that it holds its value.
Code:
test.html
---------
<a href="http://www.example.com" onclick="parent.location='counter.php?url=http://www.example.com'" target="_blank">Example.com</a>
counter.php
-----------
// Connect to DB
include_once('config.php');
// Get the URL from the variable
$url = $_GET['url'];
// Update the counter
$update = "UPDATE links SET counter = counter + 1 WHERE site_url = '$url'";
$result = mysql_query($update);
// Return to previous page
echo '<script type="text/javascript">history.go(-1);</script>';
Thank you,
M Kris
I have been working on a similar external link counter, but mine acts between the click and the redirect - i.e. the php code counts the click and then sends the user to the external page.
Ultimately its hard t prevent cheating => in my case the user would have to go back and re-click the link. There's a lot of complex solutions
BUT
What I was thinking of doing was to to add another two fields to the database
user id - computer id of the user
time - when last click to the url was made
each time the link was clicked it would check the time and user id for that URL. You could then put in a test to not update the counter if the latest user id was the same and the click occurred with say 10 seconds of the previous user.
sorry don't have the code its just an idea.
Cheers