我的網站有一個PHP登錄腳本,但if(isset($_POST['submit']))
似乎不工作。它始終以回聲"Unable to login. Please contact administrator.";
返回。該代碼是
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
require "dbc.php";
if(isset($_POST['submit']))
{
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
$enc_password = md5($password);
if($username && $password)
{
$query = mysql_query("SELECT * FROM users WHERE username='$username'");
$numrow = mysql_num_rows($query);
if($numrow!=0)
{
while($row = mysql_fetch_assoc($query))
{
$db_username = $row['username'];
$db_password = $row['password'];
}
if($username==$db_username&&$enc_password==$db_password)
{
echo "Logged in <a href='membersarea.php'>Click here to enter the members area</a>";
$_SESSION['username']=$db_username;
header("location: membersarea.php");
}
else
{
echo "Incorrect Username/Password";
}
}
else
{
echo "Incorrect Username/Password";
}
}
else
{
echo "All fields are required";
}
}
else{
echo "Unable to login. Please contact administrator.";
}
?>
<!--V0.3.5 Alpha-->
這是你在那裏輸入信息
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="description" content="Home to and its game downloads."/>
<meta name="keywords" content="Games, Downloads, Free, Fun, Game Development, Roll Ball, "/>
<meta name="author" />
<link rel="stylesheet" type="text/css" href="stylesheet.css"/>
<title>
</title>
</head>
<body>
<div id="validxhtml">
<p>
<a href="http://validator.w3.org/check?uri=referer"><img
src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a>
</p>
</div>
<div id="validcss">
<p>
<a href="http://jigsaw.w3.org/css-validator/check/referer">
<img style="border:0;width:88px;height:31px"
src="http://jigsaw.w3.org/css-validator/images/vcss-blue"
alt="Valid CSS!" />
</a>
</p>
</div>
<div id="title">
<h1 class="hcenter"></h1>
</div>
<div id="subtitle"><h2 class="hcenter">Login</h2></div>
<div id="links">
<ul>
<li><a href="index.html" title="Home">Home</a></li>
<li><a href="game.html" title="Current Games">Games</a></li>
<li>Login</li>
<li><a href="contact.html" title="Contact Me">Contact Me</a></li>
</ul>
</div>
<div id="body"><h3>Please Login</h3>
<?php if(isset($_GET['error'])){echo $_GET['error'];echo "<br />";} ?>
<form action="login.php" method="POST">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><p>
<input type="submit" value="Login">
</form>
<a href="register.php">Don't have an account? Register here.</a>
</div>
<div id="policy" class="hcenter">
<a target="_blank" href="http://privacypolicies.com/privacy/view/PUlI8q">Privacy policy</a>
</div>
<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-73371388-2', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>
<!--V0.3.5 Alpha-->
我也有最後一兩件事要說,第二個腳本它,你在你的登錄信息輸入一個,當頁面你點擊'登錄'它將它指向第一個。如果您有任何問題,請隨時詢問我。
您正在使用' mysql_ *'函數在你的代碼中。請看看這個問題,爲什麼你應該遠離他們:http://stackoverflow.com/q/12859942/4464702 – RAnders00