session unset in codeigniter not working
<p>i aam actually not able to redirect to the same page after logout in codeigniter.but when i first click on logout it redirect to the same page but the session is not removed ...than again when i click on logout the session is geeting destroyed..can neone trace the problem here.</p>

<p>controller...</p>

<pre><code>    &lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Admin extends CI_Controller
{
     public function __construct()
     {
       parent::__construct();
       $this-&gt;load-&gt;model('admin_model');

     }
     public function index()
      {


         $data['title']= 'Home';
         $this-&gt;load-&gt;view("registration_view.php", $data);

      }
      public function dashboard()//Page after sucessful Admin Login
      {


           $username= $this-&gt;input-&gt;post('username');
           $password= md5($this-&gt;input-&gt;post('password'));;


           $result = $this-&gt;admin_model-&gt;login($username,$password);
          if ($result == true) 
          {

             $this-&gt;load-&gt;view('top_menu.php');
             $this-&gt;load-&gt;view('dashboard.php');
          }
          else 
          {
                 $data = array(
                            'error_message' =&gt; 'Invalid Username or Password'
                               );
                $this-&gt;load-&gt;view('registration_view.php', $data);
          }


      }


     public function logout()//Admin Logout
     {
         $newdata = array(

                          'user_name'  =&gt;'',

                          );
         $this-&gt;session-&gt;unset_userdata($newdata );
         $this-&gt;session-&gt;sess_destroy();
         $this-&gt;load-&gt;view('top_menu.php');
     }
     public function users()//User Lists
      {

          $this-&gt;load-&gt;view('top_menu.php');
          $this-&gt;data['users'] = $this-&gt;admin_model-&gt;getUsers();
          $this-&gt;load-&gt;view('list_user.php',$this-&gt;data);


      }
      public function delete_user()//Delete Users
      {


          $id=$this-&gt;input-&gt;post('id');
          $this-&gt;admin_model-&gt;delete_user($id);



      }
      public function delete_multiple()//Delete Multiple Users
      {

        //$id = $_POST['ids'];
        //echo $data=$id;
        //$this-&gt;admin_model-&gt;delete_multiple($id);

        $this-&gt;admin_model-&gt;delete_multiple($_POST['checkedValues']);

      }
      public function add_user()//Add User Form
      {


         $this-&gt;load-&gt;view('top_menu.php');
          $this-&gt;load-&gt;view('add_user.php');
      }
      public function insert_user()//Add User Form
      {

         $this-&gt;load-&gt;library('form_validation');

        $this-&gt;form_validation-&gt;set_rules('username', 'Username', 'required');
        $this-&gt;form_validation-&gt;set_rules('password', 'Password', 'required');
        $this-&gt;form_validation-&gt;set_rules('email', 'Email', 'required');
        $this-&gt;form_validation-&gt;set_rules('contact', 'Contact', 'required');
         if ($this-&gt;form_validation-&gt;run() == FALSE)
        {
            $this-&gt;add_user();
        }
        else
        {
          $this-&gt;admin_model-&gt;insert_user();
          $this-&gt;users();   
        }


      }


}
 ?&gt;
</code></pre>

<p>logout setion in the view file...</p>

<pre><code>&lt;!-- Start: page-top-outer --&gt;
&lt;div id="page-top-outer"&gt;    
&lt;!-- Start: page-top --&gt;
&lt;div id="page-top"&gt;
    &lt;!-- start logo --&gt;
    &lt;!--&lt;div id="logo"&gt;
    &lt;a href=""&gt;&lt;img src="images/shared/logo.png" width="150" height="150" alt="" /&gt;&lt;/a&gt;
    &lt;/div&gt;--&gt;
    &lt;!-- end logo --&gt;

    &lt;div class="clear"&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;!-- End: page-top --&gt;
&lt;/div&gt;
&lt;!-- End: page-top-outer --&gt;
&lt;div class="clear"&gt;&amp;nbsp;&lt;/div&gt;
&lt;!--  start nav-outer-repeat................................................................................................. START --&gt;
&lt;div class="nav-outer-repeat"&gt; 
&lt;!--  start nav-outer --&gt;
&lt;div class="nav-outer"&gt;                 
        &lt;!-- start nav-right --&gt;
        &lt;div id="nav-right"&gt;            
            &lt;h4&gt;&lt;?php echo anchor('admin/logout', 'Logout'); ?&gt;&lt;/h4&gt;            
             &lt;div id="welcome"&gt;

             &lt;h2&gt;Hello &lt;?php echo $this-&gt;session-&gt;userdata('user_name'); ?&gt;,&lt;/h2&gt;
             &lt;/div&gt;

            &lt;div class="clear"&gt;&amp;nbsp;&lt;/div&gt;                 
        &lt;/div&gt;
        &lt;!-- end nav-right --&gt;

        &lt;!--  start nav --&gt;
        &lt;div class="nav"&gt;
            &lt;h1 style="padding-top:7px;color:#900"&gt;AdWare&lt;/h1&gt;
        &lt;/div&gt;
        &lt;!--  start nav --&gt;                                       
&lt;/div&gt;
&lt;div class="clear"&gt;&lt;/div&gt;
&lt;nav class="hk-menu"&gt;
    &lt;div class="nav-outer"&gt;
      &lt;ul class="hk-ul select" &gt;
      &lt;?php $current_url=current_url();?&gt;

            &lt;li class="&lt;?php if($current_url==base_url()."index.php/admin/dashboard") echo 'current';?&gt;"&gt;&lt;a href="list_category.php"&gt;&lt;b&gt;CATEGORY&lt;/b&gt;&lt;/a&gt;
            &lt;/li&gt;
            &lt;li class="&lt;?php if(( basename( $_SERVER["SCRIPT_FILENAME"] ) == 'list_video.php') || ( basename( $_SERVER["SCRIPT_FILENAME"] ) == 'create_user.php' ) ) echo 'current';?&gt;"&gt;&lt;a href="list_video.php"&gt;&lt;b&gt;VIDEOS&lt;/b&gt;&lt;/a&gt;

            &lt;/li&gt;
            &lt;li class="&lt;?php if($current_url==base_url()."index.php/admin/users")  echo 'current';?&gt;"&gt;&lt;?php echo anchor('admin/users', 'USERS',array('class' =&gt; 'li_style'));?&gt;
            &lt;/li&gt;
        &lt;/ul&gt;
    &lt;/div&gt;  
&lt;/nav&gt;
&lt;div class="clear"&gt;&lt;/div&gt;
&lt;!--  start nav-outer --&gt;
&lt;/div&gt;
&lt;!--  start nav-outer-repeat................................................... END --&gt;
 &lt;div class="clear"&gt;&lt;/div&gt;
&lt;!-- start content-outer --&gt;
&lt;div id="content-outer"&gt;
&lt;!-- start content --&gt;
&lt;div style="height:20px"&gt;&amp;nbsp;&lt;/div&gt;
&lt;div id="content"&gt;
&lt;style&gt;


&lt;/style&gt;
</code></pre>

<p>What i want is when "logout" is clicked the session should get destroyed and it should redirect to the view page without the session</p>