session user_id

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mankolele
    New Member
    • Sep 2006
    • 63

    session user_id

    Hi all.

    I have been reading notes on how to use sessions and cookies,I see that there is a user_id which is used to identify each user but dont see how it is generated and assigned to a particular user.

    Does anyone have a clear explanation on how its generated coz even on the insertstatement it is not there on the values??
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    Originally posted by mankolele
    Hi all.

    I have been reading notes on how to use sessions and cookies,I see that there is a user_id which is used to identify each user but dont see how it is generated and assigned to a particular user.

    Does anyone have a clear explanation on how its generated coz even on the insertstatement it is not there on the values??
    User IDs are usually generated by the database when a user is created by having a NOT NULL AUTO_INCREMENT field in the table.
    They are usually grabbed from a database when a user logs in.

    Comment

    • mankolele
      New Member
      • Sep 2006
      • 63

      #3
      Originally posted by Motoma
      User IDs are usually generated by the database when a user is created by having a NOT NULL AUTO_INCREMENT field in the table.
      They are usually grabbed from a database when a user logs in.
      Thanks for responding.

      that is exacly what I dont under stand the id I have been using is the aouto increment which starts from 1,2,3 goes on ,is it the same how do I link it to the username I just dont get the logic I guess.

      Comment

      • Motoma
        Recognized Expert Specialist
        • Jan 2007
        • 3236

        #4
        Originally posted by mankolele
        Thanks for responding.

        that is exacly what I dont under stand the id I have been using is the aouto increment which starts from 1,2,3 goes on ,is it the same how do I link it to the username I just dont get the logic I guess.
        When you insert an user into a user table with an autoincrement field, it will get assigned an ID (the next number in the sequence) . When you check to see if a user exists, you will grab the id as well as the user information:
        Code:
        SELECT user_id FROM userTable WHERE username='mankolele' and password='toasty';
        Hope this helps.

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          $_Session['user_id'] is not something that exists by default. It has no connection to any database or anything else.
          It is simply a variable, like $user_id, except it is stored in the _Session array.
          It doesnt have to be user_id, it could be i_am_bob and the php script wouldnt give a frick.
          If you want to use it, you have to create it and give it a value, just like any variable.

          User id's are passed in the _Session array pretty frequently and most coders try to use variable names that clearly identify what they represent, so it is not uncommon to see user id's stored as user_id or UserID or something simular.

          Comment

          Working...