Jump to content

Recommended Posts

Hi Everyone,

 

I have a script (displayed below) that is supposed to block direct access to certain directories using HTTP_REFERER but is proving to be unreliable due to the fact that many modern browsers (such as Firefox) and firewalls don't pass this information on correctly (or at all). My question is is there a better way to do this and does anyone have examples of code that has worked for them in the past?

 

Thanks for the help,

 

kaiman

 

<?
$referrer = $_SERVER['HTTP_REFERER'];
// set page that it is okay to access from
if (preg_match("http://www.domain.com/scripts/php/contactform.php",$referrer)) {
      header('Location: http://www.domain.com/contact/error/');
}
// otherwise redirect to another page 
else {
      header('Location: http://www.domain.com/contact/');
};
?> 

Link to comment
https://forums.phpfreaks.com/topic/249152-better-way-to-do-this/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.