Log in

View Full Version : if ip check



NXArmada
07-24-2006, 06:34 PM
i am trying to do an if ip check so that if a certain ip (namely one ip) loads the page they see additional information.

Heres what if quickly put together but is always showing true.



<?php
// Get Ipaddress
$IP = getenv("REMOTE_ADDR");

// Show IP address for test
echo "IP:".$IP;

// IF statement
if ($IP = "192.168.1.4") {
echo "yes you are John Grooms";
} else {
echo "sorry you are not John Grooms";
}
?>


The network here is on a Static Ip address so the ip does not change. Everything works up to the if statement.

Twey
07-24-2006, 06:59 PM
You've confused = with ==.

NXArmada
07-24-2006, 07:10 PM
Thanks Twey i knew it was going to be something simple as that. Thanks for the help.

Twey
07-24-2006, 07:22 PM
If you find you do this a lot, try putting a constant value on the other side of the operator, for example:
if ("192.168.1.4" == $IP) {It'll make no difference with == or ===, but if you inadvertantly use = it'll throw an error instead of just carrying on and not doing what you expect it to.

NXArmada
07-24-2006, 07:44 PM
cool thanks for the tip