PDA

View Full Version : Counting impressions


SDP2006
08-04-2003, 11:09 PM
Is there a way to tell how many clicks there has been on a certain image? Sorta what phpads does, but thats to extravagant for me. I don't need that much info.

For instance, a ad is placed on a page. Can it write to a text file how many clicks it has recieved. If so, how?


Thanks

CrAzYCoDeR969
08-05-2003, 02:07 AM
You would have to have the image point to your server but then have your server redirect or something like that to the site that the ad is for. Sorta like this:

yoursite.com/pagethatcountsclicks.php?site=whatever.com

SDP2006
08-05-2003, 02:22 AM
So, how does that tell how many clicks it gets?

AaronW
08-05-2003, 02:38 AM
Are you asking for us to write you a script or are you asking for us to explain the concept?

Basically what he was saying is that you'd need to point your image's link to a script on your server that increments a number in a file and THEN redirects to the advertised site.

SDP2006
08-05-2003, 03:02 AM
I just want to see the code that counts the impressions and then writes them to a file.

V@no.
08-05-2003, 03:10 AM
Originally posted by SDP2006
I just want to see the code that counts the impressions and then writes them to a file.
this case maybe it would be easier just look inside any ads scripts how they works...;)

Michiel
08-05-2003, 09:23 AM
Simple counter:


$filename = "counter.txt";
// Open the file in 'read-mode'
$fd = fopen ($filename, "r");
// Retrieve the contents of the file in a variable
$hits = fread ($fd, filesize ($filename));
// Close the file
fclose ($fd);

// Add new hit to the total hits
$hits = $hits+1;

// Open the file in 'write-mode'
$fd = fopen($filename, "w");
// Write the value of $hits to the file
fwrite($fd, trim($hits));
// Close the file
fclose($fd);


This can be improved in a lot of ways, but it show you the basics of a counter. Hope that helps.

Next time try to search the manual first. The code above comes almost directly from php.net.

Michiel