只需在PHP中尝试从web上复制一个登录脚本。但是它将转到logincheck.php页面,该页面显示为空白。这是完整的脚本
的login.html
<html>
<head>
<meta http-equiv="content-type" content="text/html" />
<meta name="author" content="" />
<title>Simple login</title>
</head>
<body>
<div id="login">
<h2>Simple login with PHP MYSQL</h2>
<form action="logincheck.php" method="post">
<p> Username <label><input type="text" name="uname" /></label></p>
<p> Password <label><input type="password" name="passwd" /></label></p>
<label><input type="submit" name="submit" value="Login" /></label>
</form>
</div>
</body>
</html>
logincheck.php
<?php
/**
* @author
* @copyright 2013
*/
$con=mysql_connect("localhost","root","")or die("Cannot connect to databases!");
mysql_select_db("fakebook",$con);
$u=$_POST['uname'];
$p=md5($_POST['passwd']);
$query=mysql_query("
select * from users where username='$u' and password='$p'
");
$row=mysql_num_rows($query);
if ($row == 1)
{
session_start();
$a=mysql_fetch_array($query);
$_SESSION['user']=$a['username'];
header("location: home.php");
}
else
{
header("location: login.html");
}
?>
home.php
<?php
/**
* @author
* @copyright 2013
*/
session_start();
if (isset($_SESSION['user'])){
echo "Welcome,".$_SESSION['user']."<br />
[ <a href=\"logout.php\">Logout</a> ]";
}else{
echo "You are not authorized into this page!";
}
?>
logout.php
<?php
/**
* @author
* @copyright 2013
*/
session_start();
if (isset($_SESSION['user'])){
session_destroy();
header("location: login.html");
}
else{
header("location: login.html");
}
?>
数据库名称:fakebook,表名:users
答案 0 :(得分:0)
参见http://php.net/manual/en/function.header.php 标题(&#39;位置:http://www.example.com/&#39;);它的资本L不是l。可能是这个问题。这个脚本不好/没有安全(没有转义字符串等)。你也使用mysql而不是mysqli,
答案 1 :(得分:0)
首先,您应将此代码放在checklogin.php页面的顶部以查看是否有任何错误:
error_reporting(E_ALL);
ini_set('display_errors', '1');
完成后检查错误是什么。
另外我注意到,在你的HTML表单中,它会重定向到logincheck.php,但你将文件命名为checklogin.php
答案 2 :(得分:0)
您的登录表单正在重定向到logincheck.php
。它不应该重定向到checklogin.php
吗?
如果是,请更改:
<form action="logincheck.php" method="post">
对此:
<form action="checklogin.php" method="post">