By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,639 Members | 3,105 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,639 IT Pros & Developers. It's quick & easy.

session user_id

P: 63
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??
Jan 29 '07 #1
Share this Question
Share on Google+
4 Replies


Motoma
Expert 2.5K+
P: 3,235
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.
Jan 29 '07 #2

P: 63
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.
Jan 29 '07 #3

Motoma
Expert 2.5K+
P: 3,235
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:
Expand|Select|Wrap|Line Numbers
  1. SELECT user_id FROM userTable WHERE username='mankolele' and password='toasty';
  2.  
Hope this helps.
Jan 29 '07 #4

Atli
Expert 5K+
P: 5,058
$_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.
Jan 30 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.