I just wonder what are the best practices to secure a restricted page with PHP. It has to be really safe.
I guess using the $_SESSION vars is the normal / most secure way.
Here is what I do to log in :
- I use a separate sql table with the username and an encrypted password + SALT
- SALT is randomly generated and stored in the db (is this a good practice?) at the registration
- I use filter_var and PDO on $_POST login and password to avoid sql injection
- I check the number of failed logins and set the account inactive after 3 failed attempts
- I do not use any cookie
- I use SSL
Here is my code if the login is successful, it looks so simple that I'm wondering if it is secure enough :
<?php
// login + password successful
session_start();
$_SESSION['islogged'] = true;
?>
// on each restricted page
<?php
session_start();
if(!$_SESSION['islogged']){
header('Location: unauthorized.php');
exit;
}
// here start my restricted content
?>
I wonder i.e. if using the header function this way is safe enough and 100% reliable?
For the php session security, I already found this interesting content : What are the risks of PHP sessions?
Is there something else I must be careful of?
Thank you a lot for your suggestions !