简体   繁体   English

如果用户未登录,则重定向

[英]Redirect if user not logged in

i link below the PHP part for control and redirect the user when clicking on a link. 我在PHP部分下方链接进行控制,并在单击链接时重定向用户。

session_start();
        if($_SESSION['LoggedIn']==TRUE)
        {
            //DO SOMETHING
        }
        else
        {
        header("e.g. REDIRECT TO THE PAGE IN LOCALHOST ");
        }

This is my html page / nav link 这是我的html页面/导航链接

<a class="dropdown-link" href="account.php">Il mio account</a>
<a class="dropdown-link" href="orders.php">I miei ordini</a>

is that possible to redirect the user in different page using the same file? 是否可以使用同一文件在不同页面中重定向用户?

Make a file with name like authenticate.php and include it in all pages where logged-in is required, it contains following code: 制作一个名为authenticate.php类的文件,并将其包含在需要登录的所有页面中,该文件包含以下代码:

session_start();
if($_SESSION['LoggedIn']==TRUE)
{
  //DO SOMETHING
}
else
{
  header("location: index.php");
}

If user is not logged-in, then user will be redirected to index.php 如果用户未登录,则该用户将被重定向到index.php

Try the folowing code. 尝试以下代码。 It must work in your case.Just changed the php file names: 它必须在您的情况下有效。只需更改php文件名:

session_start();
if(isset($_SESSION['LoggedIN']))
{
   header("location:home.php");
}
else
{
     header("location: login");
}

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

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