Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



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

Posts: 4
Trades: 0
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
 
 
Register now for full access!
Old 09-28-2004, 08:44 PM
vivekar's Avatar
Webmaster Talker

Posts: 612
Trades: 0
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.
__________________

Please login or register to view this content. Registration is FREE
(Active since 2003) |
Please login or register to view this content. Registration is FREE

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

Posts: 4
Trades: 0
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, 06:18 AM
Ultra Talker

Posts: 377
Trades: 0
hmm, may be i'm wrong , but couldn't it be set through .htaccess??
__________________
andrews_john

Please login or register to view this content. Registration is FREE
andrews_john is offline
Reply With Quote
View Public Profile Visit andrews_john's homepage!
 
Old 09-29-2004, 09:20 AM
ibbo's Avatar
Super Spam Talker

Posts: 880
Location: Leeds UK
Trades: 0
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, 10:30 AM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
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, 10:00 PM
vivekar's Avatar
Webmaster Talker

Posts: 612
Trades: 0
.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.
__________________

Please login or register to view this content. Registration is FREE
(Active since 2003) |
Please login or register to view this content. Registration is FREE
vivekar is offline
Reply With Quote
View Public Profile Visit vivekar's homepage!
 
Reply     « Reply to IP restrictions
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB 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.45698 seconds with 12 queries