auth.php
登录失败。它只能接受来自数据库的1个用户admin.php
header("Location: admin.php");
醇>
file:auth.php
<?php
error_reporting(E_ERROR | E_PARSE);
$settings_dir = "../settings";
include "$settings_dir/database.php";
$login=mysql_query('SELECT username, password FROM admin ');
$r=mysql_fetch_array($login);
$admin = $r['username'];
$admin_pw = $r['password'];
session_start();
if (isset($_POST['user']) && isset($_POST['pass'])) {
$username = $_POST['user'];
$password = md5($_POST['pass']);
if (($username == $admin) && ($password ==$admin_pw)) {
$_SESSION['admin'] = $username;
$_SESSION['admin_pw'] = $password;
}
header("Location: admin.php");
exit();
} elseif ((isset($_SESSION['admin']) && isset($_SESSION['admin_pw']) &&$_SESSION['admin'] == $admin && $_SESSION['admin_pw'] == $admin_pw ) || (getenv("REMOTE_ADDR")=="")) {
} else {
?>
<html>
<head>
<title>
Admin Login
</title>
<LINK REL=STYLESHEET HREF="admin.css" TYPE="text/css">
</head>
<body>
<center>
<br>
<br>
<fieldset style="width:30%;">
<legend><b>
Admin Login
</b></legend>
<form action="auth.php" method="post">
<table>
<tr>
<td>
Username
</td>
<td>
<input type="text" name="user">
</td>
</tr>
<tr>
<td>
Password
</td>
<td>
<input type="password" name="pass">
</td>
</tr>
<tr>
<td>
</td>
<td>
<input type="submit" value="Login" id="submit">
</td>
</tr>
</table>
</form>
</fieldset>
</center>
</body>
</html>
<?php
exit();
}
?>
答案 0 :(得分:-1)
file: auth.php
<?php
error_reporting(E_ERROR | E_PARSE);
$settings_dir = "../settings";
include "$settings_dir/database.php";
$login=mysql_query('SELECT username, password FROM admin ');
$r=mysql_fetch_array($login);
$admin = $r['username'];
$admin_pw = $r['password'];
session_start();
if (isset($_POST['user']) && isset($_POST['pass'])) {
$username = $_POST['user'];
$password = md5($_POST['pass']);
if (($username == $admin) && ($password ==$admin_pw)) {
$_SESSION['admin'] = $username;
$_SESSION['admin_pw'] = $password;
}
?>
<script>
window.location.href='admin.php';
</script>
<?php
exit();
} elseif ((isset($_SESSION['admin']) && isset($_SESSION['admin_pw']) &&$_SESSION['admin'] == $admin && $_SESSION['admin_pw'] == $admin_pw ) || (getenv("REMOTE_ADDR")=="")) {
} else {
?>
<html>
<head>
<title>Admin Login</title>
<LINK REL=STYLESHEET HREF="admin.css" TYPE="text/css">
</head>
<body>
<center>
<br><br>
<fieldset style="width:30%;"><legend><b>Admin Login</b></legend>
<form action="auth.php" method="post">
<table>
<tr><td>Username</td><td><input type="text" name="user"></td></tr>
<tr><td>Password</td><td><input type="password" name="pass"></td></tr>
<tr><td></td><td><input type="submit" value="Login" id="submit"></td>
</tr></table>
</form>
</fieldset>
</center>
</body>
</html>
<?php
exit();
}
?>