seb213 Posted May 7, 2008 Share Posted May 7, 2008 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 Quote Link to comment Share on other sites More sharing options...
ablueycolor Posted May 7, 2008 Share Posted May 7, 2008 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']; Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 7, 2008 Share Posted May 7, 2008 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. Quote Link to comment Share on other sites More sharing options...
seb213 Posted May 7, 2008 Author Share Posted May 7, 2008 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. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 7, 2008 Share Posted May 7, 2008 Don't use Dreamweaver. Write it yourself, without the use of programs that are going to end up hindering your skills. =/ And wait. Do you already have a table that has the affiliate information in it? Quote Link to comment Share on other sites More sharing options...
seb213 Posted May 7, 2008 Author Share Posted May 7, 2008 No, But ill create the database, insert the table, and use the php script on my index.php page, correct? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 7, 2008 Share Posted May 7, 2008 The table will be uhh: CREATE TABLE traffic ( pubid INT NOT NULL ); Quote Link to comment Share on other sites More sharing options...
seb213 Posted May 7, 2008 Author Share Posted May 7, 2008 Do i put this code in the <body> of the document? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 7, 2008 Share Posted May 7, 2008 No....use it to make the table in MySQL. Quote Link to comment Share on other sites More sharing options...
seb213 Posted May 7, 2008 Author Share Posted May 7, 2008 no, the code above the table, the code used for capturing the url string Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 7, 2008 Share Posted May 7, 2008 Oh oh. You can put it on the very top of the page before any HTML because it has no output, so it doesn't matter. =P Quote Link to comment Share on other sites More sharing options...
seb213 Posted May 7, 2008 Author Share Posted May 7, 2008 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? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 7, 2008 Share Posted May 7, 2008 Uhh...are you including this file into the other (index.php) file? If you are, then don't run mysql_close(). >_> Quote Link to comment Share on other sites More sharing options...
seb213 Posted May 7, 2008 Author Share Posted May 7, 2008 I am using this in the same index.php file as the script you wrote for me. I took out the close statement and i still get Warning: mysql_connect() [function.mysql-connect] Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 7, 2008 Share Posted May 7, 2008 <?php $link = mysql_connect('localhost', 'snack4_traffic', 'snack4_traffic'); if (!is_resource($link)) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; ?> Try it. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted May 7, 2008 Share Posted May 7, 2008 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.