该段代码用于从 user 表中检测管理员账户/密码正确与否:
<?php session_start(); require("./conn.php"); if($_POST){ $password = MD5(trim($_POST['password'])); $username = $_POST['username']; $check_result = mysql_query("SELECT uid FROM user WHERE username = '$username' AND password = '$password'"); if(mysql_fetch_array($check_result)){ session_register("username"); // 重定向至留言管理界面 header("Location: http://".$_SERVER['HTTP_HOST'].rtrim(dirname($_SERVER['PHP_SELF']), '/\' )."/admin.php"); exit; } else { echo '密码错误!'; } } ?>