所以我的问题有点令人困惑。像 Facebook 一样,您有主页。 登录后,网址保持不变,但您不会看到登录/注册页面,而是会看到新闻提要等。
我在我的网页上使用 PHP,登录后我会收到回显消息“您已登录!” 我是否可以重定向回具有网站新布局的主页,但 URL 可以保持不变?
<?php>
require('nameofit.php');
if(isset($_POST['submit'])){
$Username = mysql_escape_string($_POST['Username']);
$pass = mysql_escape_string($_POST['pass']);
$pass = md5($pass);
$sql = mysql_query("SELECT * FROM `users` WHERE `Username` = '$Username' AND `pass` = '$pass'");
if(mysql_num_rows($sql) > 0){
echo "You're logged in.";
exit();
}else{
echo "Wrong Username or Password, make sure you entered the right information.";
}
}else{
$form = <<<EOT
<form action="login.php" method="post">
Username: <input type="text" name="Username" /><br />
Password: <input type="password" name="pass" /><br />
<input type="submit" name="submit" value="Login" />
</form>
EOT;
echo $form;
}
?>
最佳答案
如果您的登录操作是POST
,您可以使用header
header('Location: ' . $_SERVER['HTTP_REFERER']);
使用它您将重定向到上一页。
或者你可以设置任何你想要的:
header('Location: index.php');
header('Location: /index.php');
header('Location: http://www.yoursite.com');
header('Location: directory/whatever/page.php');
解决方案
if (mysql_num_rows($sql) > 0) {
header('Location: ' . $_SERVER['HTTP_REFERER']);
} else {
echo "Wrong Username or Password, make sure you entered the right information.";
}
重要
不要那样做。
不要在您的 View 中执行 SELECT
或数据库中的任何内容。
关注good pratices , always update your knowledge , 使用 MVC , PDO等
关于php - 使用 MySql db 登录后关于网站的一般信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21289082/