只是尝试在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
/**
* @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
参见http://php.net/manual/en/function.header.php头(地点:http://www.example.com/);是大写L,不是L。可能是这个问题。这个脚本不是很好/安全(没有转义字符串等)。你也使用mysql而不是mysqli,
首先,你应该把这段代码放在你的checklogin.php页面的顶部,看看是否有任何错误:
error_reporting(E_ALL);
ini_set('display_errors', '1');
如果有错误,检查错误是什么。
我还注意到HTML表单重定向到logincheck。php文件命名为checklogin。php
您的登录表单正在指向logincheck.php
。它不应该指向checklogin.php
吗?
如果是,修改如下:
<form action="logincheck.php" method="post">
:
<form action="checklogin.php" method="post">