php简单的会话类代码

前端之家收集整理的这篇文章主要介绍了php简单的会话类代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<div class="codetitle"><a style="CURSOR: pointer" data="9586" class="copybut" id="copybut9586" onclick="doCopy('code9586')"> 代码如下:

<div class="codebody" id="code9586">
<?PHP
class session
{
static $sessionObject;
/ $_SESSION['user'] == 0,don't work .
== 1,he is really user .
*/
private function construct()
{
if(! ( isset($_SESSION['user']) && $_SESSION['user']==0 ))
session_set_cookie_params(3600); session_start(); //Initialize14 }15 private function
clone()
{
}
public static function getObject()
{
if(! self::$sessionObject instanceof self)
$sessionObject = new session() ; return $sessionObject;
} public function set_false()
{
$_SESSION['user'] = 0 ; // for PHP>=5
}
public function set_true()
{
if( isset($_SESSION['user']) )
$_SESSION['user'] = 1 ;
else
$this->error();
}
public function get_status()
{
return $_SESSION['user'];
}
public function end_session()
{
session_destroy();
}
public function error()
{ }
}
?>

大概用法
example :
log in page : $session = session::getObject();
$session->set_ture(); // if $row['password'] ==
next page :
<div class="codetitle"><a style="CURSOR: pointer" data="1300" class="copybut" id="copybut1300" onclick="doCopy('code1300')"> 代码如下:
<div class="codebody" id="code1300">
$session = session::getObject();
if($session->get_status())
// .... the user is really
else
// ....

log out : $session = session::getObject();
$session->end_session();
由get_status()返回当前用户是否有效登录

原文链接:https://www.f2er.com/php/27679.html

猜你在找的PHP相关文章