[英]How to redirect the user to their proper pages after login?
我想将用户重定向到他们正确的主页。 我也想将我所知道的会话保留在我的login.php
。 在我的users
表中,我存储用户名,密码和类型。
login.php
<?php
require ('connect.php');
if (isset($_POST['submit'])) {
$username = $_POST['username'];
$password = $_POST['password'];
if ($username && $password) {
$check = mysql_query("SELECT * FROM users WHERE username='".$username."' AND password= '".$password."'");
$rows = mysql_num_rows($check);
if(mysql_num_rows($check) != 0){
session_start();
$run_login =mysql_fetch_array($check);
$uid = $run_login['id'];
$_SESSION['uid'] = ['uid'];
$_SESSION['username']=$_POST['username'];
header("location:../../statistics/home.php");
}
else{
die("Could not find the Username or password.");
}
}
else {
echo "Please fill all the fields.";
}
}
?>
A.方法1
您可以使用header()函数发送新的HTTP标头,但是必须在任何HTML或文本之前(例如,在声明之前)将其发送到浏览器。
header('Location:'。$ newURL);
B.方法2
死()
header(“ Location: http : //example.com/myOtherPage.php ”);
死();
C.方法3
此功能未包含303状态代码:
function Redirect($url, $permanent = false)
{
header('Location: ' . $url, true, $permanent ? 301 : 302);
exit();
}
Redirect('http://example.com/', false);
这更加灵活:
function redirect($url, $statusCode = 303)
{
header('Location: ' . $url, true, $statusCode);
die();
}
有关更多信息,请参见: 如何在PHP中进行重定向?
把die(); 标头之后(“ location:../../ statistics / home.php”); 并检查home.php中的会话
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.