[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [cobalt-developers] php and ip check
- Subject: Re: [cobalt-developers] php and ip check
- From: Graeme Merrall <graeme@xxxxxxxxxxxxx>
- Date: Thu May 1 06:08:00 2003
- List-id: Discussion Forum for developers on Sun Cobalt Networks products <cobalt-developers.list.cobalt.com>
On Wed, Apr 30, 2003 at 11:37:51AM -0400, nick 76 wrote:
> Can someone give me a hand please.
>
> I have a client who want a php script that checks for 3 ip addresses. If
> the ip is in the "OK" list then they move foward to a webpage, if they are
> not in the "ok" list then i take them to a different web page. so far i
> found this as a starting point:
>
> <?php
>
> if (trim($REMOTE_ADDR) != "xxx.xx.xx.xx"){
> echo "<script>alert(\"Invalid IP Address(You Can't do
> this).\");history.go(-1)</script>\n";
> exit;
> }
> ?>
You could use
<?php
$list = array('xx.xx.xxx.xx', 'yyy.yy.yyy.yy', 'zz.zzz.zzz.zzz');
if (in_array(trim($REMOTE_ADDR, $list))) {
// OK
} else {
header("Location: denied.php");
}
?>
that's prob a good way as it's easy to extend the list. As usual,
there's more than one way to do it. Off the top of my head, this should
also work.
<?php
switch(trim($REMOTE_ADDR)) {
case 'xx.xx.xxx.xx':
case 'yyy.yy.yyy.yy':
case 'zz.zzz.zzz.zzz':
header("Location: ok.php");
break;
default:
header("Location: denied.php");
}
Again - a nice easy way to extend the list.
Cheers,
Graeme