SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: Sessions :(

  1. #1
    SitePoint Addict
    Join Date
    May 2001
    Posts
    217
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sessions :(

    Whats wrong with this code? it doesnt register the variables

    <?php
    session_start();
    if( !$username || !$password)
    {
    echo ("Error - all the fields are required, please go back and fill them in.");
    exit;
    }

    require ('../functions.php');

    //----------------check password------------------
    $pass = md5($password);
    $sql = "SELECT * FROM user_info WHERE (u_username = '$username')";
    $pass_word = mysql_query($sql);
    $row = mysql_fetch_array($pass_word);
    if(!$pass_word) {
    echo mysql_error(). "<br>";
    }
    $pass_check = $row["u_password"];
    if ($pass_check != $pass)
    {
    echo ("Error - Password Incorrect. Please press back and check the password");
    session_destroy();
    }

    //------Get user ID-------
    $userid = $row["u_id"];
    $fnam = $row["u_fname"];
    $lname = $row["u_lname"];
    $email = $row["u_email"];

    session_register('fnam');
    session_register('email');
    session_register('lname');
    session_register('userid');
    echo "logged in.. <a href=login.php>Continue</a>";
    ?>

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    How do you know they are not registered?

    In addition, your code is going to generate some errors if any of the if conditions are true. Sessions are using cookies behind the scenes, so you cannot send output to the browser and then try to register session variables.
    Last edited by 7stud; Jun 5, 2001 at 01:44.

  3. #3
    SitePoint Addict
    Join Date
    May 2001
    Posts
    217
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i know they are not registered, because when i re-start the session and echo the registered variable.. nothing comes up

    also, the code does not generate any errors...

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Really? Try entering a username and a password, but type in a username that is not in your table.

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually 7stud

    In addition, your code is going to generate some errors if any of the if conditions are true. Sessions are using cookies behind the scenes, so you cannot send output to the browser and then try to register session variables.
    The cookie only stores the session id, the actual data is stored in a file or in a db, so you can register session vars after headers have been sent, you just can't call session_start() after the headers are sent. And this probably has nothing to do with the question at hand, but I wanted to let everyone know that, in case they though otherwise.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmm.. maybe the session hasnt expired on your server?? coz the code seems to be fine...
    i dunno...

  7. #7
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Let's see the code where you "restart" the session.


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
  •