[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cobalt-developers] php and ip check



Thanks a ton for repsonding guys. i am stil trying to learn php and it helps when people give me alot of help.

Thanks!

From: Graeme Merrall <graeme@xxxxxxxxxxxxx>
Reply-To: cobalt-developers@xxxxxxxxxxxxxxx
To: cobalt-developers@xxxxxxxxxxxxxxx
Subject: Re: [cobalt-developers] php and ip check
Date: Thu, 1 May 2003 23:01:46 +1000

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

_______________________________________________
cobalt-developers mailing list
cobalt-developers@xxxxxxxxxxxxxxx
http://list.cobalt.com/mailman/listinfo/cobalt-developers


_________________________________________________________________
Tired of spam? Get advanced junk mail protection with MSN 8. http://join.msn.com/?page=features/junkmail