I’m working on a login script. When the user successfully logs in I set $_SESSION['logged_in'] = TRUE;
Then, I simply check on other pages if $_SESSION['logged_in'] = TRUE; If so, I display the appropriate content
Everything works fine, but now I’m adding more security. Would it be beneficial for me to check the session_id of the current user against the session_id stored in the database upon login? Would this help prevent session hijacking? If not, are there other preventative measures I should be taking?
No, it would not be beneficial to check the session_id against the one stored in the DB. If a session is hijacked that means that the hijacker has the session id. So checking it against the DB would only reveal that the the hijacker has a valid session token.
You could, as noko said, check the IP, but then that is something else you would need to store and something else you would need to do on every request. Checking the user-agent would be pointless.
The best things you can do to prvent session hijacking are:
Ideally, using it for everything is best.
UPDATE: To elaborate on #3 (as requested) I will quote from and refer to the OWASP Session Management Cheat Sheet
AND