Wrote a piece of code to perform some common operations on the session:
<?phpnamespace Home\controller; UseThink\controller;classDemo1controllerextendsController { Public functionindex () {$user= M ("City")Select (); $this->assign (' list ',$user); $this-display (); } //Session Assignment Public functionTest1 () {session (' username ', ' admin '); Session (' Useralias ', ' admin '); Echo' Session assignment '; } //Session Fetch Value Public functiontest2 () {Echo' Session value <br/> '; Echo' Username: '. session (' username '). ' <br/> '; Echo' Useralias: '. session (' Useralias '). ' <br/> '; } //Delete Session Public functionTest3 () {session (' Username ',NULL); Session (' Useralias ',NULL); Echo' Delete Session '; } //determine if the session exists Public functiontest4 () {if('? Username ')) { Echo' Username exist <br/> '; } Else { Echo' username does not exist <br/> '; } if('? Useralias ')) { Echo' Useralias exists '; } Else { Echo' Useralias does not exist '; } }}
Operation session with thinkphp