PHP SESSION Security question
Is it safe for me to use in live website?
member.php
if($_SESSION['login'] == 1)
//member stuff
$_SESSION['login']
is set after user authenticate via开发者_StackOverflow中文版 login.php
Session security in PHP is often asked about - see PHP Session Security for pretty good answers.
In general: yes. You may want to set a bit more variables, but sessions are only available to php and not the user. The part where it gets exciting in terms of security is how you handle your authentication.
Yes, you should check if $_SESSION is set too.
if(isset($_SESSION['login'])) { ...
if($_SESSION['login'] == 1) { ...
It's safe as the $_SESSION
state is stored on your server, not sent back to the client.
Using sessions is better than using cookies when checking for logins/authentication since they can be altered as it communicates with the server from client side when session are only used for server side reading.
精彩评论