I need simple php session for my special pages.

Discussion in 'PHP' started by brajeshnepal, Feb 20, 2007.

  1. #1
    I have have a website that requires the user registration before they can login but i need session help so that the pages after login are not viewed directely by putting its link on address bar. Only logged in user must be able to view that page. Some one please help me with simple session and setting up cookie.
     
    brajeshnepal, Feb 20, 2007 IP
  2. SniperFox.com

    SniperFox.com Guest

    Messages:
    154
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    So you just want some sessions set up so there are pages only users can see?

    Ok Well

    <?php
    
    session_start();
    
    if ( $_SESSION["logged_in"] == true ) {
    
    // PAGE GOES HERE
    
    }else{
    
    // NOT LOGGED IN
    
    }
    
    ?>
    PHP:
    Thats basicly what you need, So when they login set a sessision $_SESSION["logged_in"] == true; and then you can use that code i posted on all pages that you want only users to be able to see :).

    Also if you want to add a logout page then you need to use the function session_destroy(); and remember to add session_start(); at the very top of every page :D
     
    SniperFox.com, Feb 20, 2007 IP