session_start():启用session机制,在需要用到session的程序文件的最开始调用它.
session_register():注册session变量
session_unregister(): 删除session变量(一个一个删除)
session_is_registered(): 判断session变量是否注册
session_distroy(): 销毁所有session变量(所有session变量销毁)
初始化session,实例1:
- session_start();
-
- $_session=array();
- if(isset($_cookie[session_name()]))
- {
- setcookie(session_name(),'',time()-42000,'/');
- }
-
- session_destroy();
实例2
- session_start();
- $a=5;
- session_register('a');
- session_decode("<session that doesn't have a as a session variable>");
- print (session_is_registered('a')?$_session[a]:'not registered' );
实例3
-
- session_start();
- $_session['login_ok']=true;
- $_session['nome']='sica';
- $_session['inteiro']=34;
- $result=session_encode();
- echo $result;
- session_destroy();
实例4
- session_start();
- $_session['name']="yoursession";
- if(!isset($_session['initiated']))
- {
- session_regenerate_id();
- $_session['initiated']=true;
- }
- session_destroy();
实例5
- session_start();
- $_session['name']="yoursession";
- if(session_is_registered(name))
- {
- echo "指定的变量已经被注册为session<br>";
- }
- else
- {
- echo "指定的变量没有被注册为session<br>";
- }
- session_destroy();
|