I have googled this pretty much since I am new to this kind of security thing, but I still have some doubts.
SITUATION
I am developing a website for a firm (mostly with PHP of course) and I need to protect all the pages. I have made a login form and I am crypting the password with md5 in the database. I had in mind to do this:
- Login form. If the user authenticated with the correct username and
password, create a
$_SESSION["logged"] = 1; - Now you are logged. In each page of the website I check if the $_SESSION["logged"] is set and has the value of 1. If yes, I display the content of the page.
In this way, if you try to open a random page in the website, without logging, I am able to show an error page (because when I check the $_SESSION["logged"] I see that it is unset/it hasn't the value of 1).
QUESTION(s)
I have NOTHING stored in the client, I am doing everything server-side and I was wondering if this method is safe enough. I have seen around that people used this kind of approach that I thought but I have also read that they are going to encrypt the data in a session. Is that really needed?
I was also wondering: when the user (after the login) closes the website and the browser, does the session destroy automatically or I have to handle something on-close calling the session_destroy();?
As I have already said, I haven't much experience in this stuff but I guess that doing everything server-side is better. I don't want to use cookies.