mysql - php header location wont work -
i tried make ip based deny list stored ip numbers in mysql. basicly try header redirect if user's ip in array wont work. wrong?
$ip_array = array(); $ip_ban_query = mysql_query("select ip banned_ips"); while ($deny = mysql_fetch_assoc($ip_ban_query)){ $add_ip = $deny['ip']; $ip_array[] = $add_ip; } if (in_array ($_server['remote_addr'], $ip_array)) { header("location: http://www.google.com/"); exit(); }
we can simplify code here.. reducing complexity flushes away bugs. :)
// there several different methods accomplish this, , // should using statements here, both out of scope of question. $ipbanquery = sprintf("select ip banned_ips ip = '%s'", mysql_real_escape_string($_server['remote_addr'])); $result = mysql_query($ipbanquery); if (mysql_num_rows($result)) { header('location: http://www.google.com/'); exit(); }
it depends on you're calling code. extra-sure being called before output browser - stray spaces, html, or other debugging info prevent additional headers being sent. check webserver's error log see if there's wonky going on.
Comments
Post a Comment