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 5 of 5
  1. #1
    New Coder
    Join Date
    Jul 2007
    Posts
    61
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Session handling - Login in PHP

    Hi,

    I have created three .PHP files as main.php which asks for username, password and forwards it to checklogin.php which has connection details for the MySQL database.

    After entering login details on main.php, it successfully checks if the username and password entered are correct or not, and shows the appropriate message, which means that main.php and checklogin.php are working correctly.

    checklogin.php forwards the browser to the third .php script

    login_success.php


    the contents of login_success.php are as follows :

    <?php
    session_start();
    if(!session_is_registered('username')){
    header("location:main.php");
    }
    ?>

    <html>
    <body>
    Login Successful
    </body>
    </html>


    However, this file still shows Login Successful even if I clear my cache/history/cookies after typing this in the browser :

    http://mydomain/login_success.php

    instead of taking the browser to the main.php login screen

    What's wrong with the code ??


    Thanks

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    In what way did you register the SESSION variables?

  • #3
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    If you want you can check this out. Tell me if you like it
    sloppy login script link

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,151
    Thanks
    2
    Thanked 335 Times in 327 Posts
    The session_register(), session_is_registered() and session_unregister() functions are depreciated and only work when register globals are enabled. They should not be used when writing new code (these functions, along with register globals are eliminated in PHP6.) Use the global associative array $_SESSION instead.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #5
    Regular Coder
    Join Date
    Mar 2007
    Location
    Quebec
    Posts
    261
    Thanks
    6
    Thanked 7 Times in 7 Posts
    also to really make sure your sessions are gone make another file called like logout.php or something and use session_destroy to destroy the sessions.

    logout.php
    PHP Code:
    <?php
    session_start
    ();
    session_destroy();
    ?>


  •  

    Posting Permissions

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