détruire et créer une session dans la même fonction

Dans ma fonction de connection, j'aime détruire toute session, sauf une ici, c'est ma fonction:

public function out(){ $ref = $this->session->userdata('ref'); var_dump($ref); $this->session->sess_destroy(); $this->session->set_userdata('ref', $ref ); $ref = $this->session->userdata('ref'); echo '---------------------------------------<br />'; var_dump($ref); } 

mais cela ne fonctionne pas et il détruit toute la session même et quand je vérifie la ref dans la page suivante, je null

Inn in the function page j'obtiens cette sortie:

 array (size=2) 'val' => int 666 'date' => int 1397060477 --------------------------------------- array (size=2) 'val' => int 666 'date' => int 1397060477 A PHP Error was encountered Severity: Notice Message: Undefined index: last_activity Filename: drivers/Session_cookie.php Line Number: 590 Backtrace: A PHP Error was encountered Severity: Notice Message: Undefined index: session_id Filename: drivers/Session_cookie.php Line Number: 611 Backtrace: tableau (taille = 2) array (size=2) 'val' => int 666 'date' => int 1397060477 --------------------------------------- array (size=2) 'val' => int 666 'date' => int 1397060477 A PHP Error was encountered Severity: Notice Message: Undefined index: last_activity Filename: drivers/Session_cookie.php Line Number: 590 Backtrace: A PHP Error was encountered Severity: Notice Message: Undefined index: session_id Filename: drivers/Session_cookie.php Line Number: 611 Backtrace: 'val' => int 666 array (size=2) 'val' => int 666 'date' => int 1397060477 --------------------------------------- array (size=2) 'val' => int 666 'date' => int 1397060477 A PHP Error was encountered Severity: Notice Message: Undefined index: last_activity Filename: drivers/Session_cookie.php Line Number: 590 Backtrace: A PHP Error was encountered Severity: Notice Message: Undefined index: session_id Filename: drivers/Session_cookie.php Line Number: 611 Backtrace: 'date' => int 1397060477 array (size=2) 'val' => int 666 'date' => int 1397060477 --------------------------------------- array (size=2) 'val' => int 666 'date' => int 1397060477 A PHP Error was encountered Severity: Notice Message: Undefined index: last_activity Filename: drivers/Session_cookie.php Line Number: 590 Backtrace: A PHP Error was encountered Severity: Notice Message: Undefined index: session_id Filename: drivers/Session_cookie.php Line Number: 611 Backtrace: --------------------------------------- array (size=2) 'val' => int 666 'date' => int 1397060477 --------------------------------------- array (size=2) 'val' => int 666 'date' => int 1397060477 A PHP Error was encountered Severity: Notice Message: Undefined index: last_activity Filename: drivers/Session_cookie.php Line Number: 590 Backtrace: A PHP Error was encountered Severity: Notice Message: Undefined index: session_id Filename: drivers/Session_cookie.php Line Number: 611 Backtrace: tableau (taille = 2) array (size=2) 'val' => int 666 'date' => int 1397060477 --------------------------------------- array (size=2) 'val' => int 666 'date' => int 1397060477 A PHP Error was encountered Severity: Notice Message: Undefined index: last_activity Filename: drivers/Session_cookie.php Line Number: 590 Backtrace: A PHP Error was encountered Severity: Notice Message: Undefined index: session_id Filename: drivers/Session_cookie.php Line Number: 611 Backtrace: 'val' => int 666 array (size=2) 'val' => int 666 'date' => int 1397060477 --------------------------------------- array (size=2) 'val' => int 666 'date' => int 1397060477 A PHP Error was encountered Severity: Notice Message: Undefined index: last_activity Filename: drivers/Session_cookie.php Line Number: 590 Backtrace: A PHP Error was encountered Severity: Notice Message: Undefined index: session_id Filename: drivers/Session_cookie.php Line Number: 611 Backtrace: 'date' => int 1397060477 array (size=2) 'val' => int 666 'date' => int 1397060477 --------------------------------------- array (size=2) 'val' => int 666 'date' => int 1397060477 A PHP Error was encountered Severity: Notice Message: Undefined index: last_activity Filename: drivers/Session_cookie.php Line Number: 590 Backtrace: A PHP Error was encountered Severity: Notice Message: Undefined index: session_id Filename: drivers/Session_cookie.php Line Number: 611 Backtrace: Une erreur PHP a été rencontrée array (size=2) 'val' => int 666 'date' => int 1397060477 --------------------------------------- array (size=2) 'val' => int 666 'date' => int 1397060477 A PHP Error was encountered Severity: Notice Message: Undefined index: last_activity Filename: drivers/Session_cookie.php Line Number: 590 Backtrace: A PHP Error was encountered Severity: Notice Message: Undefined index: session_id Filename: drivers/Session_cookie.php Line Number: 611 Backtrace: Gravité: avis array (size=2) 'val' => int 666 'date' => int 1397060477 --------------------------------------- array (size=2) 'val' => int 666 'date' => int 1397060477 A PHP Error was encountered Severity: Notice Message: Undefined index: last_activity Filename: drivers/Session_cookie.php Line Number: 590 Backtrace: A PHP Error was encountered Severity: Notice Message: Undefined index: session_id Filename: drivers/Session_cookie.php Line Number: 611 Backtrace: Message: Indice indéfini: last_activity array (size=2) 'val' => int 666 'date' => int 1397060477 --------------------------------------- array (size=2) 'val' => int 666 'date' => int 1397060477 A PHP Error was encountered Severity: Notice Message: Undefined index: last_activity Filename: drivers/Session_cookie.php Line Number: 590 Backtrace: A PHP Error was encountered Severity: Notice Message: Undefined index: session_id Filename: drivers/Session_cookie.php Line Number: 611 Backtrace: Nom de file: drivers / Session_cookie.php array (size=2) 'val' => int 666 'date' => int 1397060477 --------------------------------------- array (size=2) 'val' => int 666 'date' => int 1397060477 A PHP Error was encountered Severity: Notice Message: Undefined index: last_activity Filename: drivers/Session_cookie.php Line Number: 590 Backtrace: A PHP Error was encountered Severity: Notice Message: Undefined index: session_id Filename: drivers/Session_cookie.php Line Number: 611 Backtrace: Numéro de ligne: 590 array (size=2) 'val' => int 666 'date' => int 1397060477 --------------------------------------- array (size=2) 'val' => int 666 'date' => int 1397060477 A PHP Error was encountered Severity: Notice Message: Undefined index: last_activity Filename: drivers/Session_cookie.php Line Number: 590 Backtrace: A PHP Error was encountered Severity: Notice Message: Undefined index: session_id Filename: drivers/Session_cookie.php Line Number: 611 Backtrace: Backtrace: array (size=2) 'val' => int 666 'date' => int 1397060477 --------------------------------------- array (size=2) 'val' => int 666 'date' => int 1397060477 A PHP Error was encountered Severity: Notice Message: Undefined index: last_activity Filename: drivers/Session_cookie.php Line Number: 590 Backtrace: A PHP Error was encountered Severity: Notice Message: Undefined index: session_id Filename: drivers/Session_cookie.php Line Number: 611 Backtrace: Une erreur PHP a été rencontrée array (size=2) 'val' => int 666 'date' => int 1397060477 --------------------------------------- array (size=2) 'val' => int 666 'date' => int 1397060477 A PHP Error was encountered Severity: Notice Message: Undefined index: last_activity Filename: drivers/Session_cookie.php Line Number: 590 Backtrace: A PHP Error was encountered Severity: Notice Message: Undefined index: session_id Filename: drivers/Session_cookie.php Line Number: 611 Backtrace: Gravité: avis array (size=2) 'val' => int 666 'date' => int 1397060477 --------------------------------------- array (size=2) 'val' => int 666 'date' => int 1397060477 A PHP Error was encountered Severity: Notice Message: Undefined index: last_activity Filename: drivers/Session_cookie.php Line Number: 590 Backtrace: A PHP Error was encountered Severity: Notice Message: Undefined index: session_id Filename: drivers/Session_cookie.php Line Number: 611 Backtrace: Message: Indice indéfini: session_id array (size=2) 'val' => int 666 'date' => int 1397060477 --------------------------------------- array (size=2) 'val' => int 666 'date' => int 1397060477 A PHP Error was encountered Severity: Notice Message: Undefined index: last_activity Filename: drivers/Session_cookie.php Line Number: 590 Backtrace: A PHP Error was encountered Severity: Notice Message: Undefined index: session_id Filename: drivers/Session_cookie.php Line Number: 611 Backtrace: Nom de file: drivers / Session_cookie.php array (size=2) 'val' => int 666 'date' => int 1397060477 --------------------------------------- array (size=2) 'val' => int 666 'date' => int 1397060477 A PHP Error was encountered Severity: Notice Message: Undefined index: last_activity Filename: drivers/Session_cookie.php Line Number: 590 Backtrace: A PHP Error was encountered Severity: Notice Message: Undefined index: session_id Filename: drivers/Session_cookie.php Line Number: 611 Backtrace: Numéro de ligne: 611 array (size=2) 'val' => int 666 'date' => int 1397060477 --------------------------------------- array (size=2) 'val' => int 666 'date' => int 1397060477 A PHP Error was encountered Severity: Notice Message: Undefined index: last_activity Filename: drivers/Session_cookie.php Line Number: 590 Backtrace: A PHP Error was encountered Severity: Notice Message: Undefined index: session_id Filename: drivers/Session_cookie.php Line Number: 611 Backtrace: 

J'utilise 3.0-dev

Essaye ça:

 public function out(){ $ref = $this->session->userdata('ref'); $this->session->sess_destroy(); // this kills the ID/cookie $this->session->sess_create(); // properly start a new session with new ID/cookie if($ref) $this->session->set_userdata('ref', $ref ); redirect(base_url().'index'); } fonction publique hors () { public function out(){ $ref = $this->session->userdata('ref'); $this->session->sess_destroy(); // this kills the ID/cookie $this->session->sess_create(); // properly start a new session with new ID/cookie if($ref) $this->session->set_userdata('ref', $ref ); redirect(base_url().'index'); } $ ref = $ this-> session-> userdata ('ref'); public function out(){ $ref = $this->session->userdata('ref'); $this->session->sess_destroy(); // this kills the ID/cookie $this->session->sess_create(); // properly start a new session with new ID/cookie if($ref) $this->session->set_userdata('ref', $ref ); redirect(base_url().'index'); } $ this-> session-> sess_destroy (); public function out(){ $ref = $this->session->userdata('ref'); $this->session->sess_destroy(); // this kills the ID/cookie $this->session->sess_create(); // properly start a new session with new ID/cookie if($ref) $this->session->set_userdata('ref', $ref ); redirect(base_url().'index'); } // cela tue l'ID / cookie public function out(){ $ref = $this->session->userdata('ref'); $this->session->sess_destroy(); // this kills the ID/cookie $this->session->sess_create(); // properly start a new session with new ID/cookie if($ref) $this->session->set_userdata('ref', $ref ); redirect(base_url().'index'); } $ this-> session-> sess_create (); public function out(){ $ref = $this->session->userdata('ref'); $this->session->sess_destroy(); // this kills the ID/cookie $this->session->sess_create(); // properly start a new session with new ID/cookie if($ref) $this->session->set_userdata('ref', $ref ); redirect(base_url().'index'); } // démarrez correctement une nouvelle session avec un nouvel ID / cookie public function out(){ $ref = $this->session->userdata('ref'); $this->session->sess_destroy(); // this kills the ID/cookie $this->session->sess_create(); // properly start a new session with new ID/cookie if($ref) $this->session->set_userdata('ref', $ref ); redirect(base_url().'index'); } si ($ ref) public function out(){ $ref = $this->session->userdata('ref'); $this->session->sess_destroy(); // this kills the ID/cookie $this->session->sess_create(); // properly start a new session with new ID/cookie if($ref) $this->session->set_userdata('ref', $ref ); redirect(base_url().'index'); } $ this-> session-> set_userdata ('ref', $ ref); public function out(){ $ref = $this->session->userdata('ref'); $this->session->sess_destroy(); // this kills the ID/cookie $this->session->sess_create(); // properly start a new session with new ID/cookie if($ref) $this->session->set_userdata('ref', $ref ); redirect(base_url().'index'); } redirection (base_url (). 'index'); public function out(){ $ref = $this->session->userdata('ref'); $this->session->sess_destroy(); // this kills the ID/cookie $this->session->sess_create(); // properly start a new session with new ID/cookie if($ref) $this->session->set_userdata('ref', $ref ); redirect(base_url().'index'); } 

Remarque:

sess_create() n'est pas documenté ici: sessions CodeIgniter

Vous devez consulter /system/libraries/Session.php pour find sess_create()

METTRE À JOUR

Lorsque vous utilisez Dev 3.0, vous devez le faire:

 $this->session->__construct(); 

thanx guys, je l'ai résolu en chargeant la session libe manully dans la fonction après la détruire … même si je charge automatiquement la session de session!

Je suppose qu'ils ne vont jamais résoudre les problèmes de session.

 public function out(){ $ref = $this->session->userdata('ref'); $this->session->sess_destroy(); $this->load->library('session'); $this->session->set_userdata('ref', $ref ); redirect(base_url().'index'); } fonction publique hors () { public function out(){ $ref = $this->session->userdata('ref'); $this->session->sess_destroy(); $this->load->library('session'); $this->session->set_userdata('ref', $ref ); redirect(base_url().'index'); } $ ref = $ this-> session-> userdata ('ref'); public function out(){ $ref = $this->session->userdata('ref'); $this->session->sess_destroy(); $this->load->library('session'); $this->session->set_userdata('ref', $ref ); redirect(base_url().'index'); } $ this-> session-> sess_destroy (); public function out(){ $ref = $this->session->userdata('ref'); $this->session->sess_destroy(); $this->load->library('session'); $this->session->set_userdata('ref', $ref ); redirect(base_url().'index'); } $ this-> load-> library ('session'); public function out(){ $ref = $this->session->userdata('ref'); $this->session->sess_destroy(); $this->load->library('session'); $this->session->set_userdata('ref', $ref ); redirect(base_url().'index'); } $ this-> session-> set_userdata ('ref', $ ref); public function out(){ $ref = $this->session->userdata('ref'); $this->session->sess_destroy(); $this->load->library('session'); $this->session->set_userdata('ref', $ref ); redirect(base_url().'index'); } redirection (base_url (). 'index'); public function out(){ $ref = $this->session->userdata('ref'); $this->session->sess_destroy(); $this->load->library('session'); $this->session->set_userdata('ref', $ref ); redirect(base_url().'index'); } 

Après avoir détruit une session, je crois que ce serait cette ligne:

 $this->session->sess_destroy(); 

Vous n'avez aucune session, donc vous ne pouvez rien y append.

Vous enregistrez les variables de la première session dans la variable $ ref, puis vous détruisez la session entière et essayez encore de mettre quelque chose en session. Donc, après la destruction, vous devez commencer une autre session. Quelque chose comme ça:

 public function out(){ $ref = $this->session->userdata('ref'); $this->session->sess_destroy(); session_start(); // put ur session_start func here if($ref) $this->session->set_userdata('ref', $ref ); redirect(base_url().'index'); } fonction publique hors () { public function out(){ $ref = $this->session->userdata('ref'); $this->session->sess_destroy(); session_start(); // put ur session_start func here if($ref) $this->session->set_userdata('ref', $ref ); redirect(base_url().'index'); } $ ref = $ this-> session-> userdata ('ref'); public function out(){ $ref = $this->session->userdata('ref'); $this->session->sess_destroy(); session_start(); // put ur session_start func here if($ref) $this->session->set_userdata('ref', $ref ); redirect(base_url().'index'); } $ this-> session-> sess_destroy (); public function out(){ $ref = $this->session->userdata('ref'); $this->session->sess_destroy(); session_start(); // put ur session_start func here if($ref) $this->session->set_userdata('ref', $ref ); redirect(base_url().'index'); } session_start (); public function out(){ $ref = $this->session->userdata('ref'); $this->session->sess_destroy(); session_start(); // put ur session_start func here if($ref) $this->session->set_userdata('ref', $ref ); redirect(base_url().'index'); } // met votre session_start en fonction ici public function out(){ $ref = $this->session->userdata('ref'); $this->session->sess_destroy(); session_start(); // put ur session_start func here if($ref) $this->session->set_userdata('ref', $ref ); redirect(base_url().'index'); } si ($ ref) public function out(){ $ref = $this->session->userdata('ref'); $this->session->sess_destroy(); session_start(); // put ur session_start func here if($ref) $this->session->set_userdata('ref', $ref ); redirect(base_url().'index'); } $ this-> session-> set_userdata ('ref', $ ref); public function out(){ $ref = $this->session->userdata('ref'); $this->session->sess_destroy(); session_start(); // put ur session_start func here if($ref) $this->session->set_userdata('ref', $ref ); redirect(base_url().'index'); } redirection (base_url (). 'index'); public function out(){ $ref = $this->session->userdata('ref'); $this->session->sess_destroy(); session_start(); // put ur session_start func here if($ref) $this->session->set_userdata('ref', $ref ); redirect(base_url().'index'); } 

La session est détruite mais pas recréée après la destruction. Peut-être que votre class de session devrait avoir une session_start dans le constructor