SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    http://TheICE.co.uk/ The Eerie Network's Avatar
    Join Date
    Apr 2001
    Location
    London in the UK.
    Posts
    293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sessions Hell!!!!!!!!!!!!

    Hi all, I was wondering if you could take a quick look at this code and tell me what is wrong with it.

    PHP Code:
    <?
    require("config.php"); // contains functions
    session_start();
    dbconnect(); // connects to mysql

    if (!isset($username)) {
        
    // login screen
        
    ?>
        <form method=get action=users.php>
        Username <input type=text name=username size=30 maxlength=50><br>
        Password <input type=password name=password size=30 maxlength=50><br>
        <input type=submit value=Submit>
        </form>
        <?

    } else {

        
    // sets username and password into sessions
        
    session_register("$username");
        
    session_register("$password");

        
    // mysql query to pull info from database
        
    $auth mysql_query("SELECT * FROM users WHERE username = '$username' AND password = '$password'");
        
    $yesorno mysql_num_rows ($auth);

        if (!
    $yesorno) {
            
    // Incorrect username or password
            
    session_unregister("$username");
            
    session_unregister("$password");
            echo 
    "Error, wrong login details";
        } else {
            
    // logged in
            
    echo "logged in";        
        }
    }


    ?>
    As you can guess i'm trying to save some sessions data, but as soon as I reload the page all the information is lost, and i'm presented with the login page again

    HELP!!!!!!!!!

    (BTW, i'm not 100% sure with this sessions stuff, but i'm sure that it should be saving some cookies to my machine, i've got my browser set to promt on cokies and nothing is happening)

    Cheers people.
    Daniel Hollands
    New: My Webcam <-- Come and watch me doing what I do
    TheICE.co.uk <-- New sites for the best in UK lifestyle and Competitions.
    The ofDan.Network Forums <-- Come and join in the fun.

  2. #2
    http://TheICE.co.uk/ The Eerie Network's Avatar
    Join Date
    Apr 2001
    Location
    London in the UK.
    Posts
    293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    STUPID STUPID STUPID

    I've figured out the problem, after spending hours looking this forum, searching the web, and reading up on as many tutorials as possable i've finally solved my problem.

    Did you guess what it was?

    In session_register() i was using '$username' insted of 'username' which was causing my problems.

    oh well, anyway, now i'm happy because this is working now.
    Daniel Hollands
    New: My Webcam <-- Come and watch me doing what I do
    TheICE.co.uk <-- New sites for the best in UK lifestyle and Competitions.
    The ofDan.Network Forums <-- Come and join in the fun.


Bookmarks

Posting Permissions

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