我设计了一个网站,允许用户使用简单的 html 表单进行注册。我希望用户在验证注册后重定向到主页并为新用户“创建帐户”显示此消息,我在互联网上找到了很多答案,但它们都是旧的和不同的 - 这很令人困惑 - 我会喜欢获得最新和最有效的方法来做到这一点。
这是我的登录代码
<?php // rnlogin.php
include_once 'rnheader.php';
echo "<h3>Member Log in</h3>";
$error = $user = $pass = "";
if (isset($_POST['user']))
{
$user = sanitizeString($_POST['user']);
$pass = sanitizeString($_POST['pass']);
if ($user == "" || $pass == "")
{
$error = "Not all fields were entered<br />";
}
else
{
$query = "SELECT user,pass FROM rnmembers
WHERE user='$user' AND pass='$pass'";
if (mysql_num_rows(queryMysql($query)) == 0)
{
$error = "Username/Password invalid<br />";
}
else
{
$_SESSION['user'] = $user;
$_SESSION['pass'] = $pass;
die("You are now logged in. Please
<a href='rnmembers.php?view=$user'>click here</a>.");
}
}
}
echo " <form method='post' action='rnlogin.php'>$error Username <input type='text' maxlength='16' name='user'
value='$user' /><br /> Password <input type='password' maxlength='16' name='pass'
value='$pass' /><br />
<input type='submit' value='Login' /> </form>"
?>
这是我主页上创建会话的代码
include_once 'rnheader.php';
if (!isset($_SESSION['user']))
die("<br /><br />You must be logged in to view this page");
$user = $_SESSION['user'];