Solved

Handling a "referer" page politely

Posted on 2008-10-28
4
242 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
selecting both the price and sum(price ) with mysql statement 5 45
google map tracking website 5 22
comma true 6 32
PHP Syntax Error 4 25
These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
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 …

786 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