Jump to content

Recommended Posts

$_SERVER['HTTP_REFERER']

I am tyring to see the url that a user comes from when they visit my site, I assumed I would need $_SERVER['HTTP_REFERER'] in index.php, as this is the first file that loads on my page.

[quote]
<?php


echo 'aaa';
echo $_SERVER['HTTP_REFERER']; [/quote]

Thats in index.php, but it just ignores it  >:( and doesn't echo anything but the aaa, am I doing something wrong here?


Link to comment
https://forums.phpfreaks.com/topic/26931-_serverhttp_referer/
Share on other sites

test.php
[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<?php
echo $_SERVER['HTTP_REFERER'];
?>
<body>
<a href="test.php">test.php
</a>
</body>
</html>[/code]


that works for me when i click the link it tells me i came from www.ukchat.ws/test.php


Regards
Liam
Link to comment
https://forums.phpfreaks.com/topic/26931-_serverhttp_referer/#findComment-123163
Share on other sites

yeah because when you type it in there was no old page which REFERED you to the new one... if you just want the page in which you are on at the moment then just use

<?php
echo $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
?>

If you do want the page that the user was refered from then your first code was correct

Regards
Liam
Link to comment
https://forums.phpfreaks.com/topic/26931-_serverhttp_referer/#findComment-123172
Share on other sites

Yeah the link has to be clicked on.

I'm not sure if HTTP_REFERER is set otherwise.... if it is, it's the link you just typed in. But technically speaking there is no referer if you type in the link in the browser window.

So if you were browsing eBay then you typed in your site, you should not see eBay as the referer.
Link to comment
https://forums.phpfreaks.com/topic/26931-_serverhttp_referer/#findComment-123176
Share on other sites

[quote author=nrobi link=topic=114638.msg466519#msg466519 date=1163265652]
Yeah the link has to be clicked on.

I'm not sure if HTTP_REFERER is set otherwise.... if it is, it's the link you just typed in. But technically speaking there is no referer if you type in the link in the browser window.

So if you were browsing eBay then you typed in your site, you should not see eBay as the referer.
[/quote]

Oh, ok. Thats what I was hoping it would do, show the page they came from, ebay in that case. Is there nothing that can do that in php?
Link to comment
https://forums.phpfreaks.com/topic/26931-_serverhttp_referer/#findComment-123180
Share on other sites

The referrer gets passed by the web browser. So if you click a link here that goes to you web site then the browser will log this site as the referrer. The browser wont log this site as the referrer if you type in your websites address in the address bar. As you have not been "referred"
Link to comment
https://forums.phpfreaks.com/topic/26931-_serverhttp_referer/#findComment-123186
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.