notset wrote:
Then in all user area pages i check if is $_SESSION['uid'] set and if this user id exists in my database.
The question: it's enough secure?
Probably, yes. Provided there aren't any other bugs in your application.
You should still watch out for session stealing and session fixation attacks - I'd recommend:
1. set session.use_only_cookies before session_start()
2. Regenerate the session ID during login.
These two steps will make session fixation / takeover, MORE DIFFICULT. It won't necessarily help, particularly if you have XSS vulnerabilities elsewhere in your app.
Can user (hacker) set his own $_SESSION['uid'] ?
Not unless they exploit a bug elsewhere in your system.
Maybe i should use a hash with user's password or something like that?
It wouldn't be any more secure do to so (in fact, it would be less secure, as two users might have the same password).
The security of your application needs to be addressed as a whole. In particular, you must have an application-wide strategy for prevention of:
- SQL injection
- HTML injection (i.e. cross-site scripting attacks)
And I strongly recommend that you consider installing some prevention of CSRF (cross-site-request-forgery) attacks.
Mark