1

Hi I am developing a website using codeigniter,php that requires secure login, The problem arises when I logout, & firstly I destroy the session but trouble is, when I click back on the browser it is displaying the Login page again.. Thanks for answers in advance

Following is my index function &
website is my controller .

public function index()
{   
    if(logged_in() )
    {
        redirect('/website/dashboard'); 
    }

    else
    {
        redirect('/website/login');
    }


}

code works for me.. But when i logout from site & press back button i am seeing my dashboard again...

my log out function :

public function logout($redirect = false)
{


    $this->CI->session->sess_destroy();
    if($redirect)
    {
        $this->CI->load->helper('url');
        redirect($redirect, 'refresh');
    }
}
Ajinkya
  • 11
  • 3
  • 3
    `when I click back on the browser it is displaying the Login page again` So isn't that good? After a logout, shouldn't it ask to login again? – asprin May 20 '14 at 07:51
  • 2
    The problem is not clear enough, we need a more proper example of what you are trying to achieve, we can't read minds ;) – SidOfc May 20 '14 at 07:52
  • are you destroying the session ? – Susheel Singh May 20 '14 at 07:58
  • See if [this](http://stackoverflow.com/a/16494565/1223045) helps – asprin May 20 '14 at 08:00
  • @asprin : sir plz check whether my logout function is correct or not ? – Ajinkya May 20 '14 at 08:04
  • If you press back, and refresh the page. Does it still show the dashboard page? Is your index function accessible on the dashboard page? Your logout function seems correct to me. – Sinan Samet May 20 '14 at 08:11
  • @sinan : No.... page shows database errors... But it is not i required.. When i press back button i should redirect to login only – Ajinkya May 20 '14 at 08:12
  • Well the code you are showing looks correct. I think we need to see more of the code. – Sinan Samet May 20 '14 at 08:17
  • @Sinan : ok. i will try something different for this issue & post it later on... Thank you all.. – Ajinkya May 20 '14 at 08:20
  • I think you need to check using ajax if the session is expired or not. As the page will not be refreshed when you click on back button, it will bring the last page from browser cache. – DShah May 20 '14 at 10:24
  • @DShah : Temporary, problem is solve with following code . This code is written in each view if(!logged_in()) { redirect('/website/login'); } – Ajinkya May 20 '14 at 12:15

1 Answers1

0

I suggest you to add something like following code to each of your VIEW page

<?php
if($this->session->userdata('session_set')!='true' )
{
     redirect('/website/login');
}?>
AkshayP
  • 2,141
  • 2
  • 18
  • 27
  • when you Logged in set session_set = true then while logging-out just $this->session->unset_userdata('session_set'); and try – AkshayP May 20 '14 at 09:31
  • On the behalf of 'session_set' , i used 'logged_in' , but it doen't solve my problem. – Ajinkya May 20 '14 at 09:48
  • & 1 function logged_in() which returns true when user logged in into site else returns false.. – Ajinkya May 20 '14 at 09:52
  • Temporary, problem is solve with following code . This code is written in each view if(!logged_in()) { redirect('/website/login'); } – Ajinkya May 20 '14 at 10:38