Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2009
    Posts
    74
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Login Control in my php

    Hi i am developing a site and it is my first professional project. here i am using login control by checking database as usual.for redirection like accessing restricted page without login i used a session variable like $_SESSION['user'] .if it is not set (session variable) by checking isset() then i redirect to login page using Header() function.

    for session to work i used session_start() (as in php.ini automatic session start is off)at starting of each page.

    one thing i am not understanding what should i do when user logout from my page.

    should i destroy session by using session_destroy() or unset() session[user] variable or completely follow another strategy to login as it is not the good way of login control please please hel this is my first post in this site.
    Last edited by deshi2003; 03-11-2009 at 05:48 PM. Reason: spelling

  • #2
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    you can use both and destroy the sessions cookie too
    PHP Code:
    unset($_SESSION['user']);
        
    if(isset(
    $_COOKIE[session_name()])) 
    setcookie(session_name(), ''time() - 1000);
    session_destroy(); 

  • #3
    Regular Coder
    Join Date
    Mar 2009
    Posts
    107
    Thanks
    15
    Thanked 0 Times in 0 Posts
    PHP Code:

    <?php
    session_start
    (); 
    unset(
    $_SESSION['user']);
    header("Location: login.php");
    exit()
    ?>
    simple logout script, just needs saving as logout.php and linking up


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •