2014-01-22 34 views
0

我目前已經在互聯網的幫助下建立了一個安全的登錄腳本,它的工作...幾乎。

如果會話未註冊,我需要它重新指向登錄頁面index.php。

請參閱下面的代碼:

 <ul class="nav navbar-nav navbar-right navbar-user"> 
     <li class="dropdown user-dropdown"> 
      <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-user"></i> 
      <?php if (login_check($mysqli) == true) : ?> 
      <?php echo htmlentities($_SESSION['username']); ?><b class="caret"></b></a> 
      <ul class="dropdown-menu"> 
      <li><a href="#"><i class="fa fa-user"></i> Profile</a></li> 
      <li><a href="#"><i class="fa fa-envelope"></i> Inbox <span class="badge">7</span></a></li> 
      <li><a href="#"><i class="fa fa-gear"></i> Settings</a></li> 
      <li class="divider"></li> 
      <li><a href="includes/logout.php"><i class="fa fa-power-off"></i> Log Out</a></li> 
      </ul> 
     </li> 
     </ul> 
    </div><!-- /.navbar-collapse --> 
    </nav> 
    <?php endif; ?> 

當前的代碼,主要包括如果登錄用戶名然而,它並沒有別的......和不保護網頁...任何幫助會讚賞...請注意我非常喜歡用PHP的noob。

我想只是使用

頭( '位置:../的index.php')......

感謝

回答

0

你可以在你的代碼的頂部把這個測試

<?php 
if(!login_check($mysqli)) { 
    header('Location: index.php'); 
    exit(0); 
} 
0

,你可以在頂部使用login_check()頁:

<?php 
if(login_check($mysqli) != true) { 
    header('Location: ...'); 
} elseif(login_check($mysqli) == true) { 
?> 
    <ul class="nav navbar-nav navbar-right navbar-user"> 
    <li class="dropdown user-dropdown"> 
    <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-user"></i> 
    <?php echo $_SESSION['username']; ?><b class="caret"></b></a> 
<!-- rest of your html --> 
<?php 
} //closing elseif 
?>