Reply
IP restrictions
Old 09-28-2004, 06:17 PM IP restrictions
Junior Talker

Posts: 4
Is there any way to control or restrict an IP address from viewing private contents. For example, I would like to set up two different home pages (but want to keep the URL the same) where IP (1) will see only Home Page (1) and IP (2) will only see Home Page (2).

Hope I'm clear on this ask.

Thanks,
Jerome
allbusiness is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 09-28-2004, 07:44 PM
vivekar's Avatar
Webmaster Talker

Posts: 539
PHP Code
-----------------
$thisIP = getenv("HTTP_CLIENT_IP");

$arrAllowedIPs = array("127.4.1.0","25.25.25.25");
$arrBannedIPs = array("127.0.0.1","127.0.0.2");

$isdenied = in_array($thisIP,$arrBannedIPs);

if($isdenied)
{
header("Location: notallowed.html " );
}
else
{
header("Location: homepage.html " );
}

Hope this helps.
__________________
| Submit URL at All the Websites Directory
| Get Certified in Web Design

Last edited by vivekar : 09-28-2004 at 07:53 PM.
vivekar is offline
Reply With Quote
View Public Profile Visit vivekar's homepage!
 
Old 09-28-2004, 08:51 PM
Junior Talker

Posts: 4
Thanks a bunch! I will try this out tonight. One quick question, should this code go between <Head></Head> or anywhere in the body?

Thanks again!

JErome
allbusiness is offline
Reply With Quote
View Public Profile
 
Old 09-29-2004, 05:18 AM
Ultra Talker

Posts: 377
hmm, may be i'm wrong , but couldn't it be set through .htaccess??
__________________
andrews_john
www.softwareforhosting.com
andrews_john is offline
Reply With Quote
View Public Profile Visit andrews_john's homepage!
 
Old 09-29-2004, 08:20 AM
ibbo's Avatar
Super Spam Talker

Posts: 880
Location: Leeds UK
Well you can control directory access simply with something like

<Limit GET>
order deny,allow
deny from all
allow from hostname 192.168.0.1
</Limit>

But to be realy funky you need some extra magik

Thus

1 RewriteEngine on
2 RewriteCond %{REMOTE_ADDR} ^192.168.0.1
3 RewriteRule /* http://your-access-redirect-url.com/ [R,L]
4 RewriteCond %{HTTP_HOST} !^$
5 RewriteRule /* http://your-no-access-redirect-url.com/ [R,L]

If you have more than 1 ip who has access to your private directory then just repeat lines 2 & 3 chaning the ip in line 2.

1 RewriteEngine on

2 RewriteCond %{REMOTE_ADDR} ^192.168.0.1
3 RewriteRule /* http://your-access-redirect-url.com/ [R,L]

2 RewriteCond %{REMOTE_ADDR} ^192.168.0.2
3 RewriteRule /* http://your-access-redirect-url.com/ [R,L]

4 RewriteCond %{HTTP_HOST} !^$
5 RewriteRule /* http://your-no-access-redirect-url.com/ [R,L]

Of course you can ommit the absolute IP address and just insert the first 3 elements like 192.168.0. remember to leave a trailing ( . ) giving everyone on that subnet access to those pages.

The inner workings of apache can let you do many amazing things and the beauty of htaccess is you dont even need to be running your own server as they act like style sheets by overriding previous definitions with those just parsed. Just bang one into a directory and go.

Does any other web servers give such configuration options to end users?

Ibbo
ibbo is offline
Reply With Quote
View Public Profile Visit ibbo's homepage!
 
Old 09-29-2004, 09:30 AM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Regarding the code that vivekar posted, that would likely be your entire index.php file. It handles forwarding the user's browser to the proper page to be displayed based on the IP. There would be no HTML tags in the file at all. Are you familiar with PHP?
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 09-30-2004, 09:00 PM
vivekar's Avatar
Webmaster Talker

Posts: 539
.htaccess method is simple to implement.

PHP method is suited for advanced web programming tasks.
Using PHP method, you can dynamically display the content based on IP ( country, language preference etc.,)

Choose which ever suits you best.
__________________
| Submit URL at All the Websites Directory
| Get Certified in Web Design
vivekar is offline
Reply With Quote
View Public Profile Visit vivekar's homepage!
 
Reply     « Reply to IP restrictions
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.14753 seconds with 12 queries