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 Link to comment https://forums.phpfreaks.com/topic/104485-solved-help-with-logging-incoming-affiliate-urls/ 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']; Link to comment https://forums.phpfreaks.com/topic/104485-solved-help-with-logging-incoming-affiliate-urls/#findComment-534895 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. Link to comment https://forums.phpfreaks.com/topic/104485-solved-help-with-logging-incoming-affiliate-urls/#findComment-534896 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. Link to comment https://forums.phpfreaks.com/topic/104485-solved-help-with-logging-incoming-affiliate-urls/#findComment-534914 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? Link to comment https://forums.phpfreaks.com/topic/104485-solved-help-with-logging-incoming-affiliate-urls/#findComment-534919 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? Link to comment https://forums.phpfreaks.com/topic/104485-solved-help-with-logging-incoming-affiliate-urls/#findComment-534923 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 ); Link to comment https://forums.phpfreaks.com/topic/104485-solved-help-with-logging-incoming-affiliate-urls/#findComment-534925 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? Link to comment https://forums.phpfreaks.com/topic/104485-solved-help-with-logging-incoming-affiliate-urls/#findComment-535550 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. Link to comment https://forums.phpfreaks.com/topic/104485-solved-help-with-logging-incoming-affiliate-urls/#findComment-535551 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 Link to comment https://forums.phpfreaks.com/topic/104485-solved-help-with-logging-incoming-affiliate-urls/#findComment-535564 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 Link to comment https://forums.phpfreaks.com/topic/104485-solved-help-with-logging-incoming-affiliate-urls/#findComment-535565 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? Link to comment https://forums.phpfreaks.com/topic/104485-solved-help-with-logging-incoming-affiliate-urls/#findComment-535575 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(). >_> Link to comment https://forums.phpfreaks.com/topic/104485-solved-help-with-logging-incoming-affiliate-urls/#findComment-535577 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] Link to comment https://forums.phpfreaks.com/topic/104485-solved-help-with-logging-incoming-affiliate-urls/#findComment-535583 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. Link to comment https://forums.phpfreaks.com/topic/104485-solved-help-with-logging-incoming-affiliate-urls/#findComment-535590 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? Link to comment https://forums.phpfreaks.com/topic/104485-solved-help-with-logging-incoming-affiliate-urls/#findComment-535591 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.