CodeIgniter, PHP and reloading the front page when session is destroyed -


i trying create web page users should able register, log in , log out. works fine, however, user required press sign out button twice page reload, or @ least that's how see it...

here's code:

this top page, log in / log out options

<div id="topmenu">         <?php          if(!isset($_session['check'])) {         echo ' welcome, <a href="/index.php/login/">log in</a> <a href="/index.php/register/">register</a> ';         }         else {         echo ' welcome, ' .$_session['name'] .'! <a href="/index.php/login/destroy/">sign out</a>';          }          ?> </div> 

here's destroy function in login controller

public function destroy()     {         session_destroy();         $this->load->view('frontpage');     } 

when sign out button pressed, frontpage view loaded, bar @ top (the topmenu div) stays same, , still shows sign out option, though session has been destroyed

from php.net:

session_destroy() destroys of data associated current session. it not unset of global variables associated session, or unset session cookie.

you have force page load, such redirect, rid of it.

replace $this->load->view('frontpage'); redirect('frontpage'); redirect controller called frontpage or redirect(current_url()); redirect current page.

you might better results using ci's session class.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -