Using session_decode
I need to d开发者_Go百科ecode session data to find out if a user currently has a session.
What would be the best way to do this, using session_decode
?
Use session_id()
to see if there is a current session. If there is no current session, it will return an empty string.
Do a print_r($_SESSION);
to see what session variables there are. Then if you need to do a specific condition
<?php
if ($_SESSION['userid']) {
// Do things
}
?>
eg
<?php
session_start();
$_SESSION['userid'] = 1;
$_SESSION['username'] = 'myusername';
$_SESSION['password'] = 'mypassword';
if ($_SESSION['username']) {
echo "Welcome " . $_SESSION['username'] . "!";
}
?>
精彩评论