Code to Track Clicks on a Banner

nam6641

Supreme Member
Joined
Nov 15, 2008
Messages
1,470
Reaction score
926
Is there a simple piece of code I can use that will allow me to track the number of clicks on a banner on my site? Something that will write to a text file and not cause any delay for the user in being redirected to the banner's site?
 
Just a thought, but you could use a little php script to do that.

Code:
<a href="http://www.example.com/banner.php?id=1"><img src.... /></a>

would be what you would use for the banner. And banner.php could look something like this:

PHP:
<?php

$file = fopen('data.txt', 'w');
fwrite($file, $_GET['id'] . '\n');
fclose($file);

?>

Very very basic, but you get the idea. It would be better to write to sql, and keep in mind if you do anything other then direct link to an offer it will cause some sort of delay (unavoidable).
 
You probably want to use this instead:

PHP:
$file = fopen('data.txt', 'a');

Otherwise, you will truncate the file every time someone clicks on the banner.

I'd actually do this:

PHP:
<?php file_put_contents('log.txt', $_GET['id']. "\n", FILE_APPEND); ?>

Only one line. :)
 
haha voyevoda is right, my bad. Listen to him, he is a much more knowledgeable guy when it comes to this sort of stuff then me :D
 
Back
Top