-2

I am new in PHP and I am making a script. Can you help, where am I wrong? I would also like to understand it not only have the code because I am learning. It is an IP ban script (Or i want it to be :D )

<?php
mysql_connect('host', 'user', 'mypasss') or die(mysql_error()); 
mysql_select_db('databse')
$ip = (isset($_SERVER)) ? $_SERVER['REMOTE_ADDR'] : $HTTP_SERVER_VARS['REMOTE_ADDR']; 
echo "Your IP: ".$ip; 

$query = mysql_query("SELECT `ip` FROM `user` WHERE `ip` = '$ip'");
$row = mysql_fetch_array($query); 

$protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https') 
            === FALSE ? 'http' : 'https';

$host     = $_SERVER['HTTP_HOST'];

$script   = $_SERVER['SCRIPT_NAME'];
$params   = $_SERVER['QUERY_STRING'];

$currentUrl = $protocol . '://' . $host . $script . '?' . $params;


if ($row) {

   header("Location: $currentUrl/ban/ban.php"); 
   exit(); 
} else {
 $sql = mysql_query("INSERT  INTO user(ip) VALUES ('".$ip."') ");
 header("Location: $currentUrl/ban/ban.php");
}

?>

Thanks for your help :)

4

1 回答 1

0

I think the error_reporting is off and therefore you get no error like "Cannot modify header information – headers already sent" because you make an echo "Your IP: ".$ip; before the header()-call and this usually will cause an error. See http://www.php.net/manual/en/function.header.php

于 2013-03-30T19:45:28.193 回答