Web Hosting Talk







View Full Version : Is this possible?


Mekhu
03-15-2005, 10:05 PM
Hey guys,

Without getting into a registration system and/or login type system, I want to restrict access to some specific pages on a website. The restriction I'm looking for is I don't want them available unless redirected from a specific domain and or specific page.

So if someone was to type in "hxxp://www.site.com/page.php", I would want a blank page or even an error to show.

Now, if the user was sent to same address from a specific page or domain, I'd want it to show.

Is this possible?

NetXL
03-16-2005, 05:35 AM
Yes, it's possible.

Mekhu
03-16-2005, 05:55 AM
lol, was hoping for maybe a slight little lead down the right path if possible ;)

andbin
03-16-2005, 06:03 AM
If I have understood, you want to be able to detect from which site/page your protected page has been requested.
This can be accomplished, at PHP level, using the variable $_SERVER['HTTP_REFERER'].

A simple example of what you can do:


<?php
if (isset ($_SERVER['HTTP_REFERER']))
{
$components = parse_url ($_SERVER['HTTP_REFERER']);

if ($components['host'] == "some-foo-site")
{
// this page is requested from the site some-foo-site
// do something!
}
}
?>


Changing some-foo-site to a valid host name.