Forum Moderators: coopster
<?PHP
$userip = ($_SERVER['REMOTE_ADDR']);
$ip = '111.111.111.111';if ($userip != $ip) {
header("Location:http://".$_SERVER['HTTP_HOST']."/path/to/file_restrict.php");
} else{
header("Location:http://".$_SERVER['HTTP_HOST']."/path/to/file_allow.php");
}
?>
This works, how would I go about specifying a 2nd or 3rd IP address to allow. I've tried using split function and I've also tried to specify like $ip2 or $ip3 and that didn't work, or I couldn't get it to work. Here is the attempts at adding other addresses to allow.
<?PHP
$userip = ($_SERVER['REMOTE_ADDR']);
$ip = '111.111.111.111';
$ip2 = '222.222.222.222';if ($userip != $ip ¦¦ $ip2) {
header("Location:http://".$_SERVER['HTTP_HOST']."/path/to/file_restrict.php");
} else{
header("Location:http://".$_SERVER['HTTP_HOST']."/path/to/file_allow.php");
}
?>
OR
<?PHP
$userip = ($_SERVER['REMOTE_ADDR']);
$ip = split("111.111.111.111","222.222.222.222","333.333.333.333");if ($userip != $ip) {
header("Location:http://".$_SERVER['HTTP_HOST']."/path/to/file_restrict.php");
} else{
header("Location:http://".$_SERVER['HTTP_HOST']."/path/to/file_allow.php");
}
?>
....HELP :-)
Thanks in advance
Although this makes perfect sense to me and I don't understand why languages don't implement it that way, that's not quite the syntax you need.
if (($userip != $ip) && ($userip != $ip2)) {
You could also place the allowed ips in an array and use in_array() [us.php.net]
if ($userip != $ip ¦¦ $ip2) {
Although this makes perfect sense to me and I don't understand why languages don't implement it that way, that's not quite the syntax you need.if (($userip != $ip) && ($userip != $ip2)) {
You could also place the allowed ips in an array and use in_array()
Ok that is working, thank you very much. I will look into the in_array() that you suggested.
Greatly appreciated :-)
Thanks,
You might want to look in to using logins and sessions or cookies to do what you want. There's been several threads here on the subject, so a search should net you more info than you need to go that route.
<?PHP
$userip = ($_SERVER['REMOTE_ADDR']);
$ip1 = '111.111.111.111';
$ip2 = gethostbyname('accountname.dyndns.org');if (($userip != $ip1) && ($userip != $ip2)) {
header("Location:http://".$_SERVER['HTTP_HOST']."/path/to/file_restrict.php");
} else{
header("Location:http://".$_SERVER['HTTP_HOST']."/path/to/file_allow.php");
}
?>
It works, however I never thought about it allowing anyone from dyndns.org but I guess if it does they still need to enter login credentials I am just trying to limit the amount of users getting to that page to begin with. One other thing is if they're not coming from "accountname.dyndns.org" than the IP address wouldn't match and then block them so...yeah this should work perfectly.
Thanks for all your help. :-)
Yeppers Vis3R exactly....
[edited by: RogueDogg at 9:59 pm (utc) on Mar. 3, 2008]