Redirect and Track Stats

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
jwalsh
Forum Contributor
Posts: 202
Joined: Sat Jan 03, 2004 4:55 pm
Location: Cleveland, OH

Redirect and Track Stats

Post 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
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post 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]
Last edited by d3ad1ysp0rk on Sat Jan 03, 2004 6:48 pm, edited 2 times in total.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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.)
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Thanks for the clarification. Edited my post.
User avatar
jwalsh
Forum Contributor
Posts: 202
Joined: Sat Jan 03, 2004 4:55 pm
Location: Cleveland, OH

Post 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
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post 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.
User avatar
jwalsh
Forum Contributor
Posts: 202
Joined: Sat Jan 03, 2004 4:55 pm
Location: Cleveland, OH

Post 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
Post Reply