2013-07-04 24 views
1

我工作的登錄功能....如何限制用戶回到以前登錄按註銷後頁

現在我有問題......這樣

1)後用戶按下注銷..

2)如果用戶點擊瀏覽器的後退按鈕..用戶可以看到他/她以前登錄的網頁...

我怎樣才能限制..用戶去退出後退出...

一切工作正常,除了這...幫助我解決這個..

這裏是LoginViewController.php

    <?php 
         session_start(); 
       header("Cache-Control: private, must-revalidate, max-age=0"); 
       header("Pragma: no-cache"); 
       header("Expires: Fri, 4 Jun 2010 12:00:00 GMT"); 

       include('GenericClasses/GenericCollectionClass.php'); 
       include('Models/UsersModel.php'); 
       include('DataObjects/Users.php'); 
       include('DatabaseAccess/DBHandler.php'); 

      if(!empty($_SESSION['user'])) 
      { 
       header("Location:loggedin.php"); 
       die(); 
      } 
       else 
       { 
      ?> 
       //Html code for LoginIndexpage 
      <?php 
      } 
       ?> 

這裏的login.php

  <?php 
      session_start(); 
      header("Cache-Control: private, must-revalidate, max-age=0"); 
      header("Pragma: no-cache"); 
      header("Expires: Fri, 4 Jun 2010 12:00:00 GMT"); 

      include('GenericClasses/GenericCollectionClass.php'); 
      include('Models/UsersModel.php'); 
      include('DataObjects/Users.php'); 
      include('DatabaseAccess/DBHandler.php'); 

     if(!isset($_SESSION['user'])) 
     { 
     header('Location: LoginViewController.php'); 
      exit(); 
     } 
      echo '<div style="background:white; text-align:right"> Login as:'.$_SESSION['user'].' 
     <a href="LogoutViewController.php" style="text-align:right">Logout</a></div>'; 

     ?> 

這裏是註銷。 php

  <?php 
     header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); 
     header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); 
     session_start(); 
     session_destroy(); 
      header("Location: LoginViewController.php"); 
      ?> 

任何建議都可以接受....

回答

1

用戶登錄後,您需要將用戶標識或郵件標識存儲在會話變量中。

而且您必須在所有頁面上添加條件,如果設置了用戶標識或郵件標識的會話變量,則用戶可以訪問該頁面,否則您必須在登錄頁面上重定向該頁面。

0

我建議在每個需要驗證的頁面檢查$_SESSION['user']。這可以使用通用的Php頁面來實現,您可以在所有需要認證的頁面中輸入include(這可能除了登錄頁面以外都可以)。因此,可以說,例如,創建一個名爲Security.php一個PHP頁面,該頁面裏面,你會碰到這樣這是從你的問題中提取如下:

if(!isset($_SESSION['user'])) 
    { 
     header('Location: LoginViewController.php'); 
     exit(); 
    } 

然後在需要用戶驗證每一個網頁,你可以包括Security.php文件在代碼的開頭。事情是這樣的:

<?php 
    include('YOUR PATH/Security.php'); 
    //Rest of your code here 
    ... 
<? 

這樣,它不會,如果用戶點擊後退按鈕,或者,如果他通過瀏覽器的URL輸入請求的頁面,如果他沒有登錄,他將被重定向關係到登錄頁面。

希望這將幫助你

0

一旦用戶登錄,您必須設置一個會話像內頁(儀表板用戶)$_SESSION['id'],你必須把條件對每個頁面即:

if(!isset($_SESSION['user_id'])){ 
header("location:login.php") 
} 

這將檢查session.Remeber的可用性來取消在logout.php

+0

會話如何創建會話ID ...我是新來這...會話 –

+0

'$ _SESSION [「USER_ID」] = $ _ POST ['userid']'在這裏會話大括號中的user_id是會話的關鍵字 –

+0

雖然我運行此.....它顯示了一些錯誤,如「頁面沒有正確重定向」 –

相關問題