这是事情: 我创建了一个登录表单,检查用户是管理员还是成员 ,然后将其重定向到正确的页面。 它运作良好。PHP登录表单错误
当用户输入不正确的用户并通过 登录页面进入某种循环时,问题就开始了。
我做错了什么?
感谢你的帮助 的login.php:
<?php
session_start(); // Starting Session
$error=''; // Variable To Store Error Message
if (isset($_POST['submit'])) {
if (empty($_POST['username']) || empty($_POST['password'])) {
$error = "חלק מהנתונים שסופקו, שגויים.";
}
else
{
// Define $username and $password
$username=$_POST['username'];
$password=$_POST['password'];
// Establishing Connection with Server by passing server_name, user_id and password as a parameter
include "config.php";
// To protect MySQL injection for Security purpose
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
// Selecting Database
$tbl_name="users";
//$db = mysql_select_db($tbl_name, $conn);
// SQL query to fetch information of registerd users and finds user match.
$query = mysql_query("select * from $tbl_name where userpassword='$password' AND username='$username'", $conn);
$rows = mysql_num_rows($query);
$dbdata = mysql_fetch_array($query) or die(mysql_error());
if ($rows == 1) {
$flag = $dbdata['admin'];
if ($flag == 1) {
$_SESSION['login_user']=$username; // Initializing Session
header("location: index.php"); // Redirecting To Other Page
} elseif($flag == 0){
$_SESSION['login_user']=$username; // Initializing Session
header("location: user.php"); // Redirecting To Other Page
} else{
session_destroy();
header("location: errorlog.php");
}}
mysql_close($conn); // Closing Connection
}}
?>
<!DOCTYPE html>
<html dir="rtl" lang="he">
<head>
<title>המסלקה| כניסת סוכנים</title>
<link href="../css/adminstyle.css" rel="stylesheet" type="text/css">
<link href="login.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="main">
<h1>ברוכים הבאים</h1>
<div id="login">
<h2>מלא טופס זה על מנת להיכנס</h2>
<form action="" method="post">
<label>שם משתמש :</label>
<input id="name" name="username" placeholder="באותיות ומספרים" type="text">
<label>סיסמה :</label>
<input id="password" name="password" placeholder="**********" type="password">
<input name="submit" type="submit" value=" התחבר ">
<span><?php echo $error; ?></span>
</form>
</div>
</div>
</body>
</html>
什么问题开始了?我们需要更好地描述你的问题。 – mccainz 2015-02-24 14:17:46
在浏览器开发者视图(Firefox其他Chrome浏览器)中运行它,查看网络面板以及浏览器看到/做什么? – simbo1905 2015-02-24 14:20:10