The reason is that [man]array_search/man returns the key if the element is found, and false if it is not found.
!$test evaluates to true when $test is false, but also when $test is 0. "1.2.3.4" is at position 0 in the array, hence when it is found, $test = 0. To correct this problem, one would test with ($test === false).
However, in this case, since you do not need to know the position of the element, you should use [man]in_array/man, as esukf suggested. You should use [man]explode/man instead of [man]split/man, since you do not need the regular expression capability of split().
$bannedip = "1.2.3.4,";
$bannedip .= "5.6.7.8,";
$bannedip .= "0.0.0.0,";
if (in_array($_GET['ip'], explode(',', $bannedip))) {
echo "IP Blacklisted";
} else {
echo "IP Allowed";
}
There is an alternative, and that is to use [man]strpos/man. In this case, you would not need to generate an array at all.
$bannedip = "1.2.3.4,";
$bannedip .= "5.6.7.8,";
$bannedip .= "0.0.0.0,";
if (strpos($bannedip, $_GET['ip']) === false) {
echo "IP Blacklisted";
} else {
echo "IP Allowed";
}