Solved

Handling a "referer" page politely

Posted on 2008-10-28
4
225 Views
Last Modified: 2013-11-05
I am trying to restrict access to a web page unless access is referred from a specific web site using:

if($_SERVER['HTTP_REFERER'] !="http://localhost/test/xrefer.php")
      {
            header( 'Location: http://10.50.1.139:8080');
      }

This snippet works (afaik) but it simply redisplays the page they came from which makes it appear as though the link isn't working. When I try to add an "echo" line above the header line to say " you can only get here from  xrefer.php" then the error message displays saying the headers have already been sent. I get that. But how can I indicate to a user that he's been redirected?

Thanks in advance
Steve
0
Comment
Question by:SteveJ
  • 2
4 Comments
 
LVL 3

Assisted Solution

by:DarkFish
DarkFish earned 100 total points
ID: 22825043
It is possible to do this, however you would need to use something other than a server side PHP script; or additional JavaScript.

You could use the PHP script to write a message and some JavaScript code, and execute the JavaScript when the page has loaded.

This gives the user X amount of time to read the message before being redirected.

In order to echo something while also using header(), you would have to add the echo() after the header() call; but you probably wouldn't see the output as the browser would be redirected almost instantly. Because of the way header redirects are handled; you are better of using a meta-refresh or some JavaScript to load the new page after X seconds. :)
0
 
LVL 15

Accepted Solution

by:
MMDeveloper earned 150 total points
ID: 22825200
darkfish is right, I'd prefer the meta refresh so you aren't relying on javascript support...


if($_SERVER['HTTP_REFERER'] != "http://localhost/test/xrefer.php"){
      echo 'You are being redirected <meta http-equiv="refresh" content="3">';
      //header( 'Location: http://10.50.1.139:8080');
}
0
 
LVL 16

Author Closing Comment

by:SteveJ
ID: 31510893
Thanks. I gave more points to MMD because he included a code snippet. If you think that's unfair, let me know, I'm not trying to be a jerk.

Thanks
0
 
LVL 15

Expert Comment

by:MMDeveloper
ID: 22826970
well it was his idea
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

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
This article discusses how to create an extensible mechanism for linked drop downs.
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 look for a specific file type in a local or remote server directory using PHP.

747 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