Re: [PHP] set multiple variables
On Fri, 1 Oct 2004 17:38:31 -0400, Joe Szilagyi <[EMAIL PROTECTED]> wrote: > Hi, I have this working: > > if ($REMOTE_ADDR == "212.3.54.65") { > header("Location: http://www.google.com/search?&q=huzzah";); > Redirect browser > exit; > } > > But I want to specify multiple IPs. What's the best recommended way for > doing that? One way would be to create an array of ips and look for it in that array: $ips = array('127.0.0.1','192.168.1.50'); if (in_array($REMOTE_ADDR, $ips)) { // do stuff } - Brad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] set multiple variables
Joe Szilagyi wrote: Hi, I have this working: if ($REMOTE_ADDR == "212.3.54.65") { header("Location: http://www.google.com/search?&q=huzzah";); Redirect browser exit; } But I want to specify multiple IPs. What's the best recommended way for doing that? There was one request for IN() fuction few hours ago. You ca either use the function suplied in the thread or use || operator: if ($REMOTE_ADDR == "212.3.54.65" || $REMOTE_ADDR == "212.3.54.64" ...) { -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] set multiple variables
On Fri, 1 Oct 2004 17:38:31 -0400, Joe Szilagyi <[EMAIL PROTECTED]> wrote: > Hi, I have this working: > > if ($REMOTE_ADDR == "212.3.54.65") { > header("Location: http://www.google.com/search?&q=huzzah";); > Redirect browser > exit; > } > > But I want to specify multiple IPs. What's the best recommended way for > doing that? > Build an array and use in_array(): $redirect_me = array ('212.3.54.65', '127.0.0.1', '192'168.0.1'); if (in_array ($_SERVER['REMOTE_ADDR'], $redirect_me)) { header ("Location: ..."); exit; } If the addresses you are targeting are ranges in CIDR format (e.g. 192.168.0.0/24), take a look at the PEAR package Net_IPv4. pb -- paul bissex, e-scribe.com -- database-driven web development 413.585.8095 69.55.225.29 01061-0847 72°39'71"W 42°19'42"N -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] set multiple variables
Hi, I have this working: if ($REMOTE_ADDR == "212.3.54.65") { header("Location: http://www.google.com/search?&q=huzzah";); Redirect browser exit; } But I want to specify multiple IPs. What's the best recommended way for doing that? thanks Joe -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php