Happy New Year everyone.
Does anybody know how I can restrict access to a page to those users coming from a specific url.

Thanks in advance

10 Years
Discussion Span
Last Post by Fest3er


Here is two simple ways to do this :

First way is to use .htaccess file :

deny from 111.222.333.444
deny from 222.333.444.555

Second way is php code :


$ipaddress = getenv("REMOTE_ADDR");

if ($ipaddress=='111.222.333.444' || $ipaddress=='222.333.444.555') {


Thanks MitkOK ,

I know htaccess file restriction , But i dont know ip address solution



If you want to restrict access to those users who clicked a link on a specific web page, you would have to use PHP and reference $_SERVER. But this value can't really be trusted. From the PHP manual:

The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

This is about as good as you can get if you want to be sure people arrive at your page by clicking a link on another specific page; there is no easy way to tell how someone arrived at a page.

Well, perhaps you could create a session cookie that stores the URL (or an ID code) of the page visited on your web site. Then the first thing your protected page does is check the cookie. If it contains the right URL or code, you set the cookie to the protected page's URL or code and allow access. If not, you send her elsewhere (maybe redirect to blank:, maybe to a random search on Google, maybe to an error). Of course, this means that *every* page of your web site must set the cookie.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.