开发者

Which is the best way ?? to save the username in session or id of the user in session?

user id or username which is better to save in session and also in mys开发者_开发问答ql which is the best way.

--> "select * from usertable where loginname=" . $_SESSION['username']; or

--> "select * from usertable where id=" . $_SESSION['id'];

whether integer comparison or string comparison which is the best comparison in SQL.


You should usually save the ID, because if you are running a fully normalised database this is the value that is most useful to you when performing other lookups.


What you are thinking doesnt really make much sense to me, really!

Integer comparison or String comparison -- Why do you think one will be faster that the other? Of course, if you go instruction by instruction Integer comparison will be faster, but why do you want that?

My answer: Stick to what ever you want. Choose the one that will be guaranteed to be unique. Plus, choosing username, isnt something great. Generate a unique ID for every user that is logged on. And store that ID into the $_SESSION[..]. Obviously, you would need to have some mechanism to validate the ID, and associate it with the username.


Integers comparison is always more accurate than strings, also you would like to consider the fact, the id is unique for each user, and there maybe an several user with the same username, that depends on your system.

I believe id comparison is the best way to go

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜