?
Solved

referer

Posted on 2009-04-08
2
Medium Priority
?
163 Views
Last Modified: 2012-05-06
hello there im trying to show if there was a referer but if there is none im getting an error

Notice: Undefined index: HTTP_REFERER in test.php on line 1
if ($_SERVER['HTTP_REFERER'] != "") {
	$ref=$_SERVER['HTTP_REFERER'];
}
 
if(eregi('sitename', $ref)) {
	echo 'good';
}else{
	echo 'bad';
}

Open in new window

0
Comment
Question by:XK8ER
  • 2
2 Comments
 
LVL 10

Expert Comment

by:Phatzer
ID: 24100998
Replace:

if ($_SERVER['HTTP_REFERER'] != "") {

with:

if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != "") {
0
 
LVL 10

Accepted Solution

by:
Phatzer earned 2000 total points
ID: 24101009
In fact, do it like this:
if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != "") {
        $ref=$_SERVER['HTTP_REFERER'];
} else {
        $ref=null;
}
 
if(eregi('sitename', $ref)) {
        echo 'good';
}else{
        echo 'bad';
}

Open in new window

0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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 …
Suggested Courses
Course of the Month13 days, 8 hours left to enroll

749 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