PHP Script to log link clicks

They have: 105 posts

Joined: Mar 2006

I want to log link clicks using a database on my website to display what user clicked on the link and the number of times that link has been clicked etc

I have a basic idea of how this might work,

Something like this?

Page but not sure about how to get the number of times the link has been clicked,

Also, what if the link is to an external website, and how do I record the number of times the link has been clicked as well as the user who clicked it?

Renegade's picture

He has: 3,022 posts

Joined: Oct 2002

What you could try doing is a sort of redirect thing:
Page

So, in redirect.php, have something that counts how many times that page was visited (might want to check where it's from too) as well is anything else you want to add to the database then at the very end, redirect to the page it's supposed to go to.

All this happens in about 2 seconds so, users don't really notice it much.

They have: 105 posts

Joined: Mar 2006

That sounds like a good option Cool how would I do that? I'm guessing using java script maybe? or asp/php would do the same?

I think your redirect page idea is prob the best way of doing it, I had an idea last night but I think it would be difficult counting the number of visists from each user to a particular link. My idea was:

On the page where the link is, get the current username thats logged in using a querystring (link.asp?user=username) Question: Can multiple querystrings be sent? for example, ?user=username, ?link=link, etc)

That username is sent to another page which asks the user if they want to continue following that link, if the user clicks 'Ok' the username is added to the database and then if I want the number of times that user clicked on the link I use row count where user=username?

Back to the redirect page idea

Before the end part that redirects the user to the page they want to see, I would need something that stores:

The total views
The users who have clicked on the link
The number of times each user has clicked on the link

I'm going to research how to start going about this but any help or code examples will be very much appresiated! Wink

Renegade's picture

He has: 3,022 posts

Joined: Oct 2002

Not entirely sure how it would be done, but I have seen similar things inplemented several times, even here at TWF.

Logging what you want is up to you, and can't really help too much on that but, I can say that at the end, all you really need is the following:

<?php
header
("Location: " . $url);
?>

He has: 8 posts

Joined: Aug 2007

You just need to write a little redirect script in PHP then send all links via that script. In code redirect.php would look something like this:

<?PHP

// decode the location you want to visit
$loc = base64_decode($_GET['loc']);

// update the number of times this particular location has been visited in your database
$sql = "UPDATE page_visits SET visits=visits+1 WHERE loc=".$loc." LIMIT 1";
$result = mysql_query($sql);

header('Location: '.$loc);

?>

Then you call redirect.php like this:

">Visit Google

You'll obviously need to have a MySQL database setup with a table called page_visits with columns for visits and loc.

I also encoded the url to make it look neater and less prone to parsing errors. I base64_encoded it because I like to be secretive sometimes.

Disclaimer: This is untested code and if it wipes you computer and starts global armageddon you can't blame me!

They have: 5 posts

Joined: Jul 2011

So, in redirect.php, accept something that counts how abounding times that page was visited (might wish to analysis area it's from too) as able-bodied is annihilation abroad you wish to add to the database again at the actual end, alter to the page it's declared to go to.All this happens in about 2 abnormal so, users don't absolutely apprehension it much.

They have: 59 posts

Joined: Aug 2011

As you have the word backlinks in your question linked to a paid backlink service?? Or is that a feature of this forum? Anyways, if I get you right you want to INCREASE backlinks and not know how you do it in general. So here you go, this is a nice resource to get you started. You will find a lot of nice high PR sites here to get som link love

They have: 12 posts

Joined: May 2011

hi,

what is the minimum amount to spend for Google Adwords?

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.