?
Solved

Handling a "referer" page politely

Posted on 2008-10-28
4
Medium Priority
?
264 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 3

Assisted Solution

by:DarkFish
DarkFish earned 400 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 600 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

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

752 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