简介:这是简单的会话类的详细页面,介绍了和php,有关的知识、技巧、经验,和一些php源码等。
class='pingjiaF' frameborder='0' src='http://biancheng.dnbcw.info/pingjia.php?id=343080' scrolling='no'>这算是草稿吧,很简单,稍后再去看一些session讲解。All right ,上代码
1 <?php
2 class session
3 {
4 static $sessionObject;
5 /* $_SESSION['user'] == 0 , don't work .
6 * == 1 , he is really user .
7 */
8 private function __construct()
9 {
10 if(! ( isset($_SESSION['user']) && $_SESSION['user']==0 ))
11 session_set_cookie_params(3600);
12
13 session_start(); //Initialize
14 }
15 private function __clone()
16 {
17 }
18 public static function getObject()
19 {
20 if(! self::$sessionObject instanceof self)
21 $sessionObject = new session() ;
22
23 return $sessionObject;
24 }
25
26 public function set_false()
27 {
28 $_SESSION['user'] = 0 ; // for PHP>=5
29 }
30 public function set_true()
31 {
32 if( isset($_SESSION['user']) )
33 $_SESSION['user'] = 1 ;
34 else
35 $this->error();
36 }
37 public function get_status()
38 {
39 return $_SESSION['user'];
40 }
41 public function end_session()
42 {
43 session_destroy();
44 }
45 public function error()
46 {
47
48 }
49 }
50 ?>
大概用法
example :
log in page : $session = session::getObject();
$session->set_ture(); // if $row['password'] ==
next page :
$session = session::getObject();
if($session->get_status())
// .... the user is really
else
// ....
log out : $session = session::getObject();
$session->end_session();
由get_status()返回当前用户是否有效登录