Jump to content

Getting Referral Url


peterpost

Recommended Posts

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


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/etc

Where 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

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.htm
how 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

[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

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());
?>
<?php
mysql_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 1

anyone 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

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.