简体   繁体   English

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

[英]Redirect logged in user from log in page

Looked around at other posts but still struggling.环顾其他帖子,但仍在挣扎。 Currently got a CRM system going.目前正在使用 CRM 系统。 User starts off in /index.php.用户从 /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';
?>

Whereby /header.php contains:其中 /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>

I need to add something like if (isset($_SESSION['u_uid'])) header("Location: to where you would be redirected when you log in --> view.php)我需要添加类似 if (isset($_SESSION['u_uid'])) header("Location: to where you would be redirected when you login --> view.php)

I'm not sure where the statement should go.我不确定该声明应该放在哪里。 And if there is any other syntax that needs to be added.以及是否需要添加任何其他语法。

Many thanks!非常感谢!

If I understand correctly, this code will help you.如果我理解正确,此代码将对您有所帮助。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM