Solved

referer

Posted on 2009-04-08
2
153 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 500 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

760 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

21 Experts available now in Live!

Get 1:1 Help Now