PDA

View Full Version : preg_match help


Richard
01-03-2003, 07:11 PM
I made the following script, but if the user's ip is for example 102.05.62.1 then it still redirects to down.php.

I want it to check if 62. is at the beginning of the ip, not in the rest of it (like 62.152.15.2) and only redirect to down.php if it is at the beginning - how ?

<?
$ipad="$REMOTE_ADDR";

if (preg_match ("/62./", "$ipad")) {
print "<meta http-equiv=\"refresh\" content=\"00; url=http://www.whatever.com/down.php\">";
} else {
print "<meta http-equiv=\"refresh\" content=\"00; url=http://www.whatever.com/xcd.php\">";
}
?>

Ökii
01-03-2003, 07:19 PM
just use substr($ipad,0,2) - quicker and less resources used.

Richard
01-03-2003, 07:35 PM
Thanks :):)

Kiwi
01-03-2003, 09:37 PM
the regex you wanted was:
/^62\./

You need to tell it to match only at the start of the string, and to escape the .