I'm not sure if I'm understanding the situation, do your users have ads that other people click on or do your users themselves click on the ads? In either case the way I would approach the problem would be to create ads that link to a php script and pass an id belonging to the owner of the ad via url. For example your ad might look something like this:
<a href="http://yoursite.com/redirect.php?id=11111">Your Ad Here</a>
id would be a unique id corresponding to the owner of the ad. Now on the backend you will want to find the user corresponding to that id in a MySQL database and increment a counter representing the number of clicks. Then you will forward the user who clicked the ad to their intended destination using the header command. A simple mock up will look something like this:
PHP Code:
<?php
$id = $_GET['id'];
$sql = 'SELECT * FROM `users` WHERE `id` = \''.$id.'\' LIMIT 1;';
$result = mysql_query($sql);
if($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$count = $row['count'];
}
else
{
//failed to interface with database so just forward the user to their
//location
header('Location: http://destination.com/');
}
$count++;
$sql = 'UPDATE `user` SET `count` = \''.$count.'\' WHERE `id` = \''$id'\';';
mysql_query($sql);
header('Location: http://destination.com');
?>
I left out some details such as the database information. You should also store the ip addresses of the users who have clicked the ads so someone won't take advantage of the system by repeatedly clicking the ad.
Now when it comes time for the user to download something on your site just check how many points they have and decrease it by one once they download. Feel free to contact me if you have questions. Also if you want someone to code this up for you I'm willing (provided that the job pays  my rent and tuition don't pay themselves).
Last edited by NullPointer; 09-06-2007 at 05:57 AM..
|