2017-04-11 149 views
0

我在链接PHP部件下方进行控制,并在点击链接时重定向用户。如果用户未登录,重定向

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

这是我的html页面/导航链接

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

是可以使用相同的文件在不同的页面将用户重定向?

+1

我假设你问[require](http://php.net/require)/ [include](http:// php.net/include)? –

+0

是的,但我需要更改单击链接时重定向的页面 –

+0

无法正确地得到问题。你能详细说明吗? –

回答

0

请与名称的文件中像authenticate.php并将其包含在需要登录的所有页面,它包含以下代码:

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

如果用户没有登录,则用户会被重定向到index.php

+0

是的,请在* account.php *和* orders.php *中包含此脚本/代码... – butterFlyNick

0

试试看下面的代码。它必须在你的case.Just改变了PHP文件名:

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