When a user logs in to a website, I save user_idto SESSION to check later if the user is logged in or not.
user_id
if(!empty($_SESSION['user_id'])){ ....
Is this enough for security?
This will depend entirely on how this variable goes to the session and how well you manage the session.
, - , - , . ? , ?
- , , $_SESSION ['user_id'], . , VALUE , $_SESSION ['user_id'], , .
, , , - / ( , ?). , .
, - .
.
isset():
isset()
function loggedIn() { if (isset($_SESSION['user_id']) && is_numeric($_SESSION['user_id'])) return true; return false; }
, 0, empty() true!
empty()
- , cookie , .
, , "", , IP- , , . , , , - .
...
- $_SESSION ['user_id'] = $_GET ['user_id'], : .
, , , - ..
if(!isset($_SESSION($user_id){
, $user_id == 0 then isempty() , , , .
unset($_session_variable_name);
, , .. .
, , , IP- USER_AGENT, .