does anyone knows the alternative to the deprecated function session_is_registered i开发者_JAVA百科n PHP5?
here's my code:
ob_start();
session_start();
if(!session_is_registered(myusername))
{
header("location:main_login.php");
}
ob_flush();
Thanks,
Mauro
"You need to set and reference $_SESSION variables only." For example:
if( isset($_SESSION[$myusername]) )
From http://www.phpfreaks.com/forums/index.php?topic=263189.0
on a side note, best use $_SESSION['username'] = $myusername;
. Using the $_SESSION[$myusername]
as a variable may overwrite existing variables in the session.
But if you set anything in the session variable it will display you the protected page: e.g.,
<?php
session_start();
if(isset($_SESSION[$myusername])){
echo "welcome to protected page.";
}
else {
header('location:login.php');
die;
}
?>
Use session_id()
if (!session_id()) {
// do stuff
}
if there is no session id nothing will be returned. (docs - session_id() )
精彩评论