restricting site access

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
phpcoder
Forum Contributor
Posts: 158
Joined: Sat Nov 02, 2002 1:18 pm
Location: Manchester, UK

restricting site access

Post by phpcoder »

how can i restrict any site to specific ip. i.e site can only be access from specified IP on local intranet..
plz help
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

if you're using apache as webserver you might set an "allow from" directive in httpd.conf or .htaccess. http://httpd.apache.org/docs/mod/mod_access.html#allow

If you want to do it with php (or have to), $_SERVER['REMOTE_ADDR'] contains the IP of the visitor.
http://www.php.net/manual/en/reserved.variables.php
User avatar
lazy_yogi
Forum Contributor
Posts: 243
Joined: Fri Jan 24, 2003 3:27 am

Post by lazy_yogi »

that may not be the solution though.
how can i restrict any site to specific ip. i.e site can only be access from specified IP on local intranet..

My flatmates and I are on the same LAN and $_SERVER['REMOTE_ADDR'] gives the same ip for each of us. I think it gives the ip of the interface router instead of our individual ip's.

_________________________________________________________

sounds like u might need to use a cookie

Specific IP often means a specific computer.
So when on that computer just put this in a script and run the script once (more doesn't make any diff, but wont hurt it)

Code: Select all

<?php
    setcookie('___mysecurity___', '');
?>
then at the very top of each of ur scripts put this line (before anything else at all)

Code: Select all

<?php
if (! isset($_COOKIE['___mysecurity___']))  exit;
?>
the other alternative is sessions
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

from specified IP on local intranet
I doubt the local intranet is routed through a NAT-server ;)
Post Reply