peterpost Posted November 8, 2006 Share Posted November 8, 2006 Hi there,I just got started on a php website, and would like to know if there is some built in function that catches the url where the visitor came from. or if there is a good article somewhere on the topic, i don't exactly know what to do a search on.any pointers to help me with this would be great.regards,Peter Link to comment https://forums.phpfreaks.com/topic/26616-getting-referral-url/ Share on other sites More sharing options...
brendandonhue Posted November 8, 2006 Share Posted November 8, 2006 The closest you'll get is $_SERVER['HTTP_REFERER'] which contains the "referer" header sent by the browser (can be faked/forged so don't make your script dependent on it.) Link to comment https://forums.phpfreaks.com/topic/26616-getting-referral-url/#findComment-121741 Share on other sites More sharing options...
blear Posted November 8, 2006 Share Posted November 8, 2006 The variable $_SERVER is an array of a bunch of server values that each page can access.$_SERVER['HTTP_REFERER'] will give you the url of the page that directed the user to the current page.[code]foreach($_SERVER as $var=> $val){echo "<BR>VAR:$var VAL:$val";}[/code]will dump all the values in $_SERVER to the screen in the form:VAR:HTTP_REFERER VAL:www.redirectto.com/dir/lib/etcWhere VAR is the index of the $_SERVER array and VAL is its associated value. Lots of useful information in that array, check it out. Link to comment https://forums.phpfreaks.com/topic/26616-getting-referral-url/#findComment-121743 Share on other sites More sharing options...
peterpost Posted November 8, 2006 Author Share Posted November 8, 2006 Wow thanks, this PHP stuff is great, and so is this board. fantastic mate, that did just what i was looking for.perhaps you would like to discuss some more advanced features, Cause I now face a new problem which is that I get http://www.refferringurl.com/referringpage.htmhow do i get it shortened to http://www.refferringurl.com so that i can count incomming from different page on domain? Link to comment https://forums.phpfreaks.com/topic/26616-getting-referral-url/#findComment-121752 Share on other sites More sharing options...
peterpost Posted November 8, 2006 Author Share Posted November 8, 2006 ;D It feels like somebody just ripped open pandora's box and handed it to me.Gonna play around with this a little, but I'll be back for some more goodies later.thanks for your help peeps! Link to comment https://forums.phpfreaks.com/topic/26616-getting-referral-url/#findComment-121755 Share on other sites More sharing options...
blear Posted November 8, 2006 Share Posted November 8, 2006 [code]$url = "http://www.refferringurl.com/referringpage.htm";$kapow = explode('/',$url);$shortUrl = $kapow[2];[/code]You might need $kapow[1] instead.. I usally just output the entire array after I've exploded a string to see what it looks like, then pick out the indexes that have what I need. Link to comment https://forums.phpfreaks.com/topic/26616-getting-referral-url/#findComment-121756 Share on other sites More sharing options...
peterpost Posted November 8, 2006 Author Share Posted November 8, 2006 Ok, I now have this:[code]<?php require_once('Connections/blabla.php'); ?><?php$url = $_SERVER['HTTP_HOST'];mysql_select_db($database_dbname, $blabla);$query_topref = "SELECT url, `in` FROM topref WHERE url = '$url'";$topref = mysql_query($query_topref, $blabla) or die(mysql_error());$row_topref = mysql_fetch_assoc($topref);$totalRows_topref = mysql_num_rows($topref);$een = $row_topref['in']+1;$query_topref = sprintf("UPDATE topref SET in='$een' WHERE url = '$url'", $colname_topref);$put_topref = mysql_query($query_topref, $blabla) or die(mysql_error());?><?phpmysql_free_result($topref);?>[/code]I saved this as a php file and included it in my page.but then i get the following :You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''in'='2' WHERE 'url' = 'www.refferingurl.com'' at line 1anyone got any tips at what i'm doing wrong, I've done something similar with outgoing and that works just fine, i had to alter it a bit to get the url in, so that's probably the cause.regards, Peter Link to comment https://forums.phpfreaks.com/topic/26616-getting-referral-url/#findComment-121798 Share on other sites More sharing options...
peterpost Posted November 8, 2006 Author Share Posted November 8, 2006 Ok, I got it to add to the database now, thanks again. Link to comment https://forums.phpfreaks.com/topic/26616-getting-referral-url/#findComment-121816 Share on other sites More sharing options...
brendandonhue Posted November 9, 2006 Share Posted November 9, 2006 If you're trying to get the referer, there needs to be a $_SERVER['HTTP_REFERER'] in your code. Also keep in mind that if you put links to the top referers on your site or something like that, you'll be open to referer spam. Link to comment https://forums.phpfreaks.com/topic/26616-getting-referral-url/#findComment-122077 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.