» Site Navigation | | | » Advertisement | | | » Recent Threads | | | | | | | | | | | |  |  | [PHP]IP Allowing |  |
12-30-2008, 08:49 AM
|
#1 (permalink)
| Full Member
Join Date: Dec 2008 Location: In a fun, dark, and warm place. Posts: 480
GPoints: 7,568 Rep Power: 4 | [PHP]IP Allowing This is a simple code I made, it just checks if your IP is in the list of allowed IPs. PHP Code: <?
$allow[0]="0.0.0.0";
if (in_array($_SERVER['REMOTE_ADDR'],$allow))
{
echo "Welcome" ;
}
else echo "You are not authorized to view this page."
?> Replace 0.0.0.0 with the allowed IP. | |
| |
12-30-2008, 09:19 AM
|
#2 (permalink)
| Full Member
Join Date: Dec 2008 Location: Maryland Age: 20 Posts: 911
GPoints: 12,210 Rep Power: 8 | Awesome! Except, this is a source code not a tutorial sorry  | |
| |
12-30-2008, 09:20 AM
|
#3 (permalink)
| I don't never troll
Join Date: Jun 2009 Location: live? wut. Posts: 6,912
GPoints: 16,708 Rep Power: 30 | I was thinking the same thing >> | |
| |
12-30-2008, 09:39 AM
|
#4 (permalink)
| Full Member
Join Date: Dec 2008 Location: In a fun, dark, and warm place. Posts: 480
GPoints: 7,568 Rep Power: 4 | Oh. Well can you move it?
EDIT: Just realized you already moved /facepalm.
EDIT #2: If you want more allowed IPs, use this code: PHP Code: <?
$allow[0]="0.0.0.0";
$allow[1]="0.0.0.0";
$allow[2]="0.0.0.0";
$allow[3]="0.0.0.0";
if (in_array($_SERVER['REMOTE_ADDR'],$allow))
{
echo "Welcome" ;
}
else echo "You are not authorized to view this page."
?>
Last edited by Snarf; 12-30-2008 at 09:46 AM..
| |
| |
12-30-2008, 10:28 AM
|
#5 (permalink)
| Banned
Join Date: Feb 2008 Posts: 2,646
GPoints: 1,623 Rep Power: 0 | Just edit that into your first post. | |
| |
01-01-2009, 09:00 AM
|
#6 (permalink)
| Donor
Join Date: Mar 2008 Location: Naples, Italy Age: 17 Posts: 470
GPoints: 13,176 Rep Power: 9 | A much easier way is to have a file which will have all the allowed IPs in (one per line). Say, for example, that the file is called "ipsallowed.txt", the code would be rather easy: PHP Code: <?php
if (preg_match('/^'.preg_quote($_SERVER['REMOTE_ADDR']).'$/m', @file_get_contents('ipsallowed.txt')))
{
echo 'Allowed';
}
else
{
echo 'Not allowed';
}
?> | |
| |
01-06-2009, 12:25 AM
|
#7 (permalink)
| I don't never troll
Join Date: Jun 2009 Location: live? wut. Posts: 6,912
GPoints: 16,708 Rep Power: 30 | PHP Code: if(in_array($ip,explode(",",$bannedIps))){ die("MOAR LIKE BANNED. AMIRIGHT?!");}
$bannedIps is the string with IPs separated by a comma. | |
| |  | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Thread Tools | | | | Display Modes | Linear Mode |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | |