Jump to content

[SOLVED] Help with logging incoming affiliate url's ?


seb213

Recommended Posts

Hi,

 

My situation is as follows, thanks for any help you can give.

 

I need to log individual affiliate urls coming into my site. My link affiliate will send traffic to me, each with a unique url eg. ' http://www.my-site.com/?pubid=#PUBLISHER_ID ' where 'PUBLISHER_ID' is a unique number like '12345'. I need to save each incoming URL  presumably in a MYSQL database where i can use php to print it out.

 

Anyone know the best way to achieve logging unique incoming URL'S, or maybe a framework that does this well?

 

-Steve

This was copied directly from php.net (http://us.php.net/manual/en/reserved.variables.server.php):

 

'HTTP_REFERER'

    The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

 

You can access this using the $_SERVER superglobal: $_SERVER['HTTP_REFERER'];

Uhh...

<?php
//First connect to mysql db.  This script assumes you have. 
if (isset($_GET['pubid'])) {
$pubid = (int) $_GET['pubid'];
$query = "INSERT INTO traffic (pubid) VALUES ('$pubid')";
$result = mysql_query($query) or die (mysql_error());
if (mysql_affected_rows() != 1) {
  //query was bad!  Something went wrong.
  echo "Error querying database!";
  print_r(debug_backtrace());
 }
}
//REST OF CODE FOR NORMAL SITE HERE.  That code ONLY adds it to the database (without the user knowing) if there is a pubid on the end.  You MAY want to add a check to make sure the publisher_id actually exists and has a record in your db so they don't put like pubid=232839238. =P
?>

 

 

NEVER use $_SERVER['HTTP_REFERER'].  It's not always sent, and you can modify it in like, 2 seconds if you know what you're doing.

Hi,

 

Thanks for the quick reply.  Please bare with me i have limited PHP skills.

 

A question: Based on your script, the table i need to create is 'traffic' right? And this script will instert the url variable into the table 'traffic'?

 

 

Also, can you write a connection file for me? I would use dreamweaver but id like to have a good template for future pages.

Your such a huge help, thanks for taking the time out for me.

 

Can i ask, what is wrong with my connection file? i get an unable to connect error and im sure the user name and password are correct. Im also sure i created the datebase and added the user to the database.

 

<?php

$link = mysql_connect('localhost', 'snack4_traffic', 'snack4_traffic');

if (!$link) {

    die('Could not connect: ' . mysql_error());

}

echo 'Connected successfully';

mysql_close($link);

?>

 

is it the localhost that is causing it not to connect?

 

 

NEVER use $_SERVER['HTTP_REFERER'].  It's not always sent, and you can modify it in like, 2 seconds if you know what you're doing.

 

$_SERVER['HTTP_REFERER'] is often used and is unavoidable if you want to know where someone came from. Is there another alternative?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.