/    Sign up×
Community /Pin to ProfileBookmark

Make it so only specified IP address can see site

In PHP, how can I make it so only a specified IP address can see a website? All other users will be directed to another website?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NogDogNov 20.2009 — [code=php]
<?php
$allowedIps = array(
'1.2.3.4',
'1.2.4.6'
);
if(!in_array($allowedIps, $_SERVER['REMOTE_ADDR']))
{
header('Location: http://some.other.site/');
exit;
}
?>
<!-- rest of page -->
[/code]
Copy linkTweet thisAlerts:
@SrWebDeveloperNov 21.2009 — OP: Please be informed - if the visitor comes through a proxy or firewall on their end their WAN IP might be the same as anyone else on their LAN. So you might intend to block one user but might end up blocking many sharing that IP. Plus if your filter allows wildcards to ban ranges, one typo and you could ban an entire class C, B or huge block of unintended addresses with one unnoticed typo. And even proxy servers can be used to bypass an IP ban anyway unless you implement an anti-blocking script. In short, there are a few notable potential headaches if this kind of policy is not applied sensibly and carefully.

-jim
Copy linkTweet thisAlerts:
@NogDogNov 21.2009 — OP: Please be informed - if the visitor comes through a proxy or firewall on their end their WAN IP might be the same as anyone else on their LAN. So you might intend to block one user but might end up blocking many sharing that IP. Plus if your filter allows wildcards to ban ranges, one typo and you could ban an entire class C, B or huge block of unintended addresses with one unnoticed typo. And even proxy servers can be used to bypass an IP ban anyway unless you implement an anti-blocking script. In short, there are a few notable potential headaches if this kind of policy is not applied sensibly and carefully.

-jim[/QUOTE]


I was under the impression from the original post that the OP wanted to whitelist one or a small number of IPs, not blacklist a limited number or range of IP addresses.

In either case, this could also be handled at the web server level such as limiting access to a directory via a .htaccess entry (if Apache), though I'd have to do a little Googling to come up with the syntax for that.
Copy linkTweet thisAlerts:
@SrWebDeveloperNov 24.2009 — I was under the impression from the original post that the OP wanted to whitelist one or a small number of IPs, not blacklist a limited number or range of IP addresses.[/quote]

Understood, the implications I listed work in reverse, too, i.e. you can let a whole LAN segment in if their caching proxy is bound to a single IP, for example. The main point is using IP's is subject to consequences, so be aware and carefully setup any filters. That's all. ?

-jim
×

Success!

Help @comptech520 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...