Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果用户已经在php mysql中登录,如何将用户重定向到配置文件页面_Php_Mysql - Fatal编程技术网

如果用户已经在php mysql中登录,如何将用户重定向到配置文件页面

如果用户已经在php mysql中登录,如何将用户重定向到配置文件页面,php,mysql,Php,Mysql,我有一个带有登录字段id和password的主页,如果用户使用id和password登录,它会重定向到profile.php,工作正常,但当我打开新选项卡时,它会再次显示登录页面,而不是配置文件页面。 这是我的密码 <?php session_start(); include('includes/config.php'); if(isset($_POST['login'])) { $status='1'; $email=$_POST['username']; $password=md5(

我有一个带有登录字段id和password的主页,如果用户使用id和password登录,它会重定向到profile.php,工作正常,但当我打开新选项卡时,它会再次显示登录页面,而不是配置文件页面。 这是我的密码

<?php
session_start();

include('includes/config.php');
if(isset($_POST['login']))
{
$status='1';
$email=$_POST['username'];
$password=md5($_POST['password']);
$sql ="SELECT email,password FROM users WHERE email=:email and password=:password and status=(:status)";
$query= $dbh -> prepare($sql);
$query-> bindParam(':email', $email, PDO::PARAM_STR);
$query-> bindParam(':password', $password, PDO::PARAM_STR);
$query-> bindParam(':status', $status, PDO::PARAM_STR);
$query-> execute();
$results=$query->fetchAll(PDO::FETCH_OBJ);
if($query->rowCount() > 0)
{
$_SESSION['alogin']=$_POST['username'];

echo "<script type='text/javascript'> document.location = 'profile.php'; </script>";
} else{

echo "<script>alert('Invalid Details Or Account Not Confirmed');</script>";

}

}

?>
如果用户已经登录,如果在新选项卡或新窗口中打开,如何将用户重定向到profile.php

这是管理目录中的同一登录页

<?php
session_start();
if(isset($_SESSION['alogin'])){
 header('Location: dashboard.php');
}
include('includes/config.php');
if(isset($_POST['login']))
{
$email=$_POST['username'];
$password=md5($_POST['password']);
$sql ="SELECT UserName,Password FROM admin WHERE UserName=:email and Password=:password";
$query= $dbh -> prepare($sql);
$query-> bindParam(':email', $email, PDO::PARAM_STR);
$query-> bindParam(':password', $password, PDO::PARAM_STR);
$query-> execute();
$results=$query->fetchAll(PDO::FETCH_OBJ);
if($query->rowCount() > 0)
{
$_SESSION['alogin']=$_POST['username'];
echo "<script type='text/javascript'> document.location = 'dashboard.php'; </script>";
} else{

  echo "<script>alert('Invalid Details');</script>";

}

}

?>
这是logout.php,两者都是相同的,只是目录不同

<?php
session_start(); 
$_SESSION = array();
if (ini_get("session.use_cookies")) {
    $params = session_get_cookie_params();
    setcookie(session_name(), '', time() - 60*60,
        $params["path"], $params["domain"],
        $params["secure"], $params["httponly"]
    );
}
unset($_SESSION['login']);
session_destroy(); // destroy session
header("location:index.php"); 
?>

问题是,如果我在不同选项卡的同一窗口中登录,如果我登录用户,则管理员也登录,如果我注销其中任何一个,则用户或管理员都注销,那么您可能会将此代码添加到php代码中。这是你应该做的

<?php
session_start();
if(isset($_SESSION['alogin'])){
 header('Location: profile_page.php');
}

希望它能帮助你,像这样的问题很多。

这能回答你的问题吗?现在我有一个新的问题,我有user和admin,问题是如果我从admin/index.php登录,如果我从base directory index.php以用户身份登录,那么在new tab中,这两个都是单独登录的,但是如果我注销admin,那么注销用户就是你的整个代码。如果没有请提供所有的编码,请提供代码或项目的屏幕截图,尝试删除“会话”\u destroy`已经尝试过我不是一个开发人员开始学习管理和用户数据库表是不同的一个是管理表和一个是用户表