Solved

getenv("HTTP_REFERER") returns empty string!?

Posted on 2003-11-24
3
1,138 Views
Last Modified: 2013-12-12
mail("My  Name <me@domain.com>", date("D, M j, Y - h:i a T", time()), "Connection from " . getenv("REMOTE_HOST") . " referred by " . getenv("HTTP_REFERER"), "From: \"Server Access!\" <server@site_server.com>");

I put this on my index page to mail me whenever someone visits my site. The referer returns the URL of my own bookmarks page, sited on the same server as this site, but under a different virtual domain name, but when others visit the site, the referer is blank, perhaps an empty string or a NULL. Why is the referer not being detected? Is there a way to fix it? Bonus question: can I get the IP address resolved with a reverse domain name lookup directly inside this little script?
0
Comment
Question by:mschrimsher
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
JakobA earned 250 total points
ID: 9815394
when a page is reached through javascript  (fx  self.location.href="yourpage.html")  the HTTP_REFERER is empty.  if people are directed to your site from a google search HTTP_REFERER will be set only if googles server remebers to set it in a header before they redirect.

So you cannot expect referrer to always be set.

You should not fetch it with the getenv function though, use the $_SERVER array:

 mail("My  Name <me@domain.com>", date("D, M j, Y - h:i a T", time()), "Connection from " . getenv("REMOTE_HOST") . " referred by " . $_SERVER["HTTP_REFERER"], "From: \"Server Access!\" <server@site_server.com>");

regards JakobA
0
 
LVL 15

Expert Comment

by:JakobA
ID: 9815406
0
 

Author Comment

by:mschrimsher
ID: 9815426
Jakob: Thanks! I find that about half the referers are being reported now, so I guess I just had a run of bad luck in the beginning. I do get a lot of Google traffic due to AdSense, so that may be part of it--I will correlate the IP addresses to the blank referers and see if there's a pattern. The reference to $_SERVER that you sent said that it was a version 4.1 introduction, and I am using
a 3.x version of PHP now. My ISP offers 4.x as as module, and I have planned to move over for other reasons anyway, so when I do, I will change to $_SERVER. Thanks again!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Load google maps api into wordpress 5 37
WordPress syntax 2 27
html input type 3 22
datetime in sql 6 28
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now