This is more of a server side programming question than flash. Anyhow you could simply add a unique id to each different banner. All that would be left is, when clicked, PHP or ASP reads the ID and increments the number of times that banner has been read.
In PHP you could do this a number of ways. I'll illustrate the absolute easiest (non-database). Just reading and writing to a text file.
- Your banner will include clickTAG as a URL argument, e.g. http://www.somewhere.com?clickTAG=1
After that you can simply write each ID and its value to a delimited text file. I'll use newlines and equal signs to separate values.
After the PHP page is hit, it will look for clickTAG, get the ID, read a text file, incremenet that ID and save the text file.
The text file (say bannerclicks.txt) looks like this:
Representing banner id 1 was clicked 100 times. Banner id 2 was clicked 29 times. Banner id abc123 was clicked 14 times.
# check for clickTAG, and that its not empty
if ( (isset($_GET['clickTAG'])) && (!empty($_GET['clickTAG'])) )
# a simple cleanse clickTAG from injections
$_GET['clickTAG'] = htmlspecialchars($_GET['clickTAG']);
# read all previous ids from text file into an array
$ids = file("bannerclicks.txt");
# save a flag for if this value was updated, otherwise we'll need to add it
$foundValue = FALSE;
# iterate over ids, find this id
foreach ($ids as &$id)
# inexpensive stristr match against this id
if (stristr($id, $_GET['clickTAG'] . '='))
# found the value
$foundValue = TRUE;
# extract the id and value separately (yes this could be done with a preg_replace in one step, I'm keeping it easy)
list($itemID, $itemValue) = explode("=", $id);
# increment value
# re-assign the reference
$id = $itemID . '=' . $itemValue;
# didn't find value? add it
if ($foundValue === FALSE)
array_push($ids, $_GET['clickTAG'] . '=1');
# save file
$filehandle = fopen("bannerclicks.txt","w");
Security always being my utmost concern, all I did here to prevent injections was convert any value sent via clickTAG to HTML entities, e.g. < to <. That doesn't guarantee no injections but it makes it harder.
A better security model is to decide what a valid id can be and modify the security to suit. Like an ID can only be 4 digits followed by 4 letters and use a regular expression to match against it, otherwise discard it.
hello, thanks for reply.
I had a look at your answer, but maybe I should not have been clear in my question I, sorry for my English.
I would not know the number of clicks, but well the number of impressions made by a banner
from what I understand from your script, here I am going to count and save the number of clicks for each banner
Thank you for your help
// send request that banner abc123 has been loaded
// function called from actionscript banner
// create ajax request sending the bannerID received to the PHP file