我是PHP的新手,我正在创建一个脚本。你能帮忙吗,我哪里错了? 我也想了解它不仅有代码,因为我正在学习。这是一个IP禁令脚本(或者我希望它是: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");
}
?>
感谢您的帮助:)
答案 0 :(得分:0)
我认为error_reporting已关闭,因此您不会收到类似“无法修改标头信息 - 标头已发送”的错误,因为您在echo "Your IP: ".$ip;
之前拨打了header()
- 这通常会导致错误。见http://www.php.net/manual/en/function.header.php