php - 从登录页面重定向登录用户

标签 php redirect mysqli error-handling header

环顾了其他职位,但仍在挣扎。目前已经有了CRM系统。用户从/index.php开始。

<?php
include_once'header.php';   
?>

<section class="main-container">
<div class="main-wrapper">
    <h2>Motoko</h2>

    <?php   

        if (isset($_GET["msg"]) && $_GET["msg"] == 'failed') {
        echo "Incorrect Username/Password";
        } 
        else { if (empty($uid) || empty($pwd))
        echo "You are not logged in";
            }                   
    ?>
</div>
</section>
<?php
include_once 'footer.php';
?>

其中/header.php包含:
<?php
session_start();
?>

<!DOCTYPE html>
<html>
<head>
<title>Motoko</title>
<link rel="stylesheet" type="text/css" href="style.css">

</head>
<body>
<header> 
<nav>
    <div class="main-wrapper">
        <ul>
            <li><a href="index.php">Home</a></li>   
        </ul>
        <div class="nav-login">
            <?php
                if (isset($_SESSION['u_id'])){
                echo '<form action="includes/logout.inc.php" method="POST">
                <button type="submit" name="submit">Logout</button>
                </form>';
                } else {
                echo '<form action="includes/login.inc.php" method="POST"> 
                <input type="text" name="uid" placeholder="Username/e-mail">
                <input type="password" name="pwd" placeholder="password">
                <button type="submit" name="submit">Login</button> 
                </form>';

                echo '<form action="signup.php" method="POST"> 
                <button type="submit">Sign up</button> 
                </form>';

                echo '<form action="reset.php" method="POST"> 
                <button type="submit">Forgot your Password?</button> 
                </form>';

                }
            ?>
        </div>
    </div>
</nav>
</header>

我需要添加类似if(isset($ _ SESSION ['u_uid']))header(“Location:”的位置:登录到-> view.php时将重定向到的位置)

我不确定该声明应该去哪里。并且是否需要添加任何其他语法。

非常感谢!

最佳答案

如果我理解正确,那么此代码将为您提供帮助。

if (isset($_SESSION['u_uid']))
    echo ('<script type="text/javascript">window.location.replace("http://yoursite.com/yourpath.php");</script>');

关于php - 从登录页面重定向登录用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48654231/

相关文章:

javascript - 调用 javascript 警报后,php 代码未执行

php - 显示外键数据(名称等),而不仅仅是 HTML 表中的外键

python - 获取 admin_only 装饰器的重定向循环

asp.net-mvc-3 - ASP.NET MVC : Passing a string parameter to an action using RedirectToAction()

php - php 和 MySQLi 的递归菜单

php - 连接数据库时防止SQL注入(inject)

php - mysqli_fetch_object 不返回某些表中字符串中的重音符号

php - 从外部页面提取信息

php - 无法在数据发布上建立 mysql 连接

php - 用 sed 替换模式中的字符