Page 1 of 1

Redirect and Track Stats

Posted: Sat Jan 03, 2004 4:55 pm
by jwalsh
Hi,

I'm trying to write an advertising script. Each advertising client has their own URL. These urls are displayed on a number of my pages. The clients will buy a number of times they're page is visitied. Basically it's a pay per click program. When someone clicks their banner, they are sent through a redirect script to the appropriate site.

Here's the problem. I need to be able to track the number of times each page is clicked on, and stop displaying when it gets to the number they paid for. I couldn't find a script for this, or any sample code to get me started.

Can anyone lead me in the right direction?

Thanks,

Josh

Posted: Sat Jan 03, 2004 5:06 pm
by d3ad1ysp0rk
uhh, you'd need to add 1 to the current database files for their "clicks" variable or w/e, such as:

Code: Select all

<?php
//connect to DB
$id = $_GET['id'];
$linksql = "SELECT `link` FROM `table` WHERE `id` = '$id'";
$link = mysql_result(mysql_query($linksql);
$sql = "UPDATE `table` SET `clicks` = `clicks`+1 WHERE `id` = '$id'";
mysql_query($sql) or die("Error: Could not Update Clicks.");
header("Location:$link");
?>
and then have a function on the other site that echos a random link (one that hasnt been clicked the max amount of times) or something..

[edited]

Posted: Sat Jan 03, 2004 5:46 pm
by JAM
Just adding:

Code: Select all

$sql = "UPDATE table SET clicks = clicks+1 where id = $id";
(You can add 'clicks' using a single update clause rather than the posted fetch-add-update way & added the id as you need to know what link was clicked.)

Posted: Sat Jan 03, 2004 6:44 pm
by d3ad1ysp0rk
Thanks for the clarification. Edited my post.

Posted: Sat Jan 03, 2004 8:05 pm
by jwalsh
I actually haven't even begun coding anything yet... I'm still in the planning phase. You're saying I should create a database with all my customers, and update it as the clicks come in.

That's not the problem, Most of my ads are on servers other than my own. The only way I could think of to accomplish this would be to redirect to somewhere on my site, with an ID field, then update my database from my own server... Am I correct in thinking this?

Also, I need this fairly quickly, and time is money to me. Does anyone know if there's a script for sale that would offer this functionality? or is it simple enough that a semi-newbie could put it together in reasonable time?

Thanks,

Josh

Posted: Sat Jan 03, 2004 8:18 pm
by Paddy
You were correct in thinking that. They click, redirects to your site, updates the DB, redirects to the link if they have enough 'click credit' else redirects to another site.

It is rather easy, I would suggest you either write it yourself or put this in the help wanted section.

By the way, do you have control of these other sites your banners are on? If not someone could change the URL to just go to the site required and bypass your database facility and therefore never have to pay for clicks. Just a side not for you to think about if you are in that situation.

Posted: Sat Jan 03, 2004 8:27 pm
by jwalsh
Hi,

I'm a decent programmer, but new to php. Right now I do have control over the URL's the ads are on, but that may change. I'm going to create a database, and create some dummy accounts. Then start coding. Thanks for all your help.

Josh