Forum Moderators: coopster

Message Too Old, No Replies

Defining a variable that has multiple parts

Is it this part, or this part, or this part...?

         

Jeremy_H

5:19 pm on Apr 17, 2006 (gmt 0)

10+ Year Member



I have a growing list of IP addresses I would like to show alternate content for.

When I had one IP address, I used the following line of code:

if(GetHostByName($REMOTE_ADDR)!="0.0.0.1"){}else{}

then for two, I used:

if(GetHostByName($REMOTE_ADDR)!=("0.0.0.1"¦¦"0.0.0.2")){}else{}

Now, I'm getting a larger and larger list, and I would also like to place comments about who's IP address each one is.

I was thinking about doing something like:

if(GetHostByName($REMOTE_ADDR)!=$iplist){}else{}

But I don't know how I should define the $iplist variable.

Any suggestions would be greatly appreciated.

sned

5:26 pm on Apr 17, 2006 (gmt 0)

10+ Year Member



You could use arrays as one option:

$ip_list = array(
'Some guy'=>'0.0.0.1',
'Another guy'=>'0.0.0.2',
'Third guy'=>'0.0.0.3
) ... etc.

if(in_array(GetHostByName($REMOTE_ADDR), $ip_list)){
// show content
}
else{
// show other content
}

-sned