Preventing Users from using the back button to view restricted pages after logout.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • roshni86
    New Member
    • Jul 2007
    • 1

    Preventing Users from using the back button to view restricted pages after logout.

    I have the following code for a logout of an account in php.However it is not working,as when i press the "back" button,the page returns to the previous page where a user had signed and viewed.

    [code=php]<?php
    //start the session
    session_start() ;

    //check to make sure the session variable is registered
    if(session_is_r egistered('user id')){

    //session variable is registered, the user is ready to logout
    session_unset() ;
    session_destroy ();
    }
    else{

    //the session variable isn't registered, the user shouldn't even be on this page
    header( "Location: login1.php" );
    }
    ?>[/code]

    [Please use CODE tags when posting source code. Thanks! --pbmods]

    Pleeeeaase help :(
    Last edited by pbmods; Jul 14 '07, 03:18 PM. Reason: Changed case and added CODE tags.
  • mwasif
    Recognized Expert Contributor
    • Jul 2006
    • 802

    #2
    Use only this code in your logout page

    [PHP]//start the session
    session_start() ;

    //session variable is registered, the user is ready to logout
    session_unset() ;
    session_destroy ();

    // define here the next page address
    header( "Location: login1.php" );
    exit;[/PHP]

    Are you verifying the user session correctly on the previous page?

    Please do not ask questions in CAPS.

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Heya, roshni86. Welcome to TSDN!

      To effectively prevent this, you need to block the browser from caching the page. Check out this article.

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Changed thread title to better describe the problem.

        Comment

        Working...