SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict Resident Evil's Avatar
    Join Date
    May 2003
    Location
    Barrow
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Setting Sessions

    Hi, I Want To ask iff there is a way to get everything from a database and set one session for it, iff that makes sense.

    so for example in my database, i have

    username, password, name, address

    i want to know iff u can set a session during login like,

    $user_info

    and then inside the site, use $user_info['username'] + $user_info['password'].

    I Think That Makes Sense.

    And Also When Setting a Session Is The Correct Way

    Code:
    session_register('username');
    $_SESSION['username'] == $username;
    Thanks In Advance,

    Resident

  2. #2
    Mal Reynolds Mandibal's Avatar
    Join Date
    Aug 2003
    Location
    Columbus
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    $_SESSION['username'] == $username;
    Is I think the prefered method now. Also setting session variables during login from a user table is quite common.
    Erh

  3. #3
    SitePoint Addict Resident Evil's Avatar
    Join Date
    May 2003
    Location
    Barrow
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i mean so i dont have to set each session seperately
    just select everything from the database for that user, and use $user_info to set all sessions..
    iff u get that?

  4. #4
    Mal Reynolds Mandibal's Avatar
    Join Date
    Aug 2003
    Location
    Columbus
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure if I do or not.

    $_SESSION['user_info'] can be an array itself. I guess you could just say:
    Code:
    $_SESSION['user_info'] = mysql_fetch_array($result);
    So the array returned by mysql_fetch_array from your db query will be in the session variable. Is that it?
    Erh

  5. #5
    SitePoint Addict Resident Evil's Avatar
    Join Date
    May 2003
    Location
    Barrow
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i think so.

    so then in the site.
    i can then use $user_info['username']; for example
    to call the username.

    rather than $_SESSION['username'];

    is that what u mean?

  6. #6
    Mal Reynolds Mandibal's Avatar
    Join Date
    Aug 2003
    Location
    Columbus
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No you would use $_SESSION['user_info']['username'] instead of $user_info['username'].
    Erh

  7. #7
    SitePoint Addict Resident Evil's Avatar
    Join Date
    May 2003
    Location
    Barrow
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok pld, i guess that will be ok :P

    so

    $_SESSION['user_info'] = mysql_fetch_array($result);

    would set all things from the database table into a session? am i right?

  8. #8
    Mal Reynolds Mandibal's Avatar
    Join Date
    Aug 2003
    Location
    Columbus
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sets all things from a row from a query result set.

    So if you did:
    PHP Code:
    $sql "select username, password, email from user_table where user_id='blah'";
    $result mysql_query($sql);
    $_SESSION['user_info'] = mysql_fetch_array($result); 
    You'd have the username, password and email info for user with id blah in the session variable. If you did "select * from..." you'd have all fields from your table for the given user, etc.
    Erh

  9. #9
    SitePoint Addict Resident Evil's Avatar
    Join Date
    May 2003
    Location
    Barrow
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks, thats what i wanted


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
  •