• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Session variable related issue

#1
[eluser]Aziz Chouhan[/eluser]
how can i check session variables when one could click on browser back button,after logout from the site

#2
[eluser]Mirge[/eluser]
They would see a cached version of the page if anything. Upon refresh (assuming you have code in place that IS checking to make sure they are logged in), they wouldn't be able to access anything they're not supposed to.

#3
[eluser]Aziz Chouhan[/eluser]
but i don't want to see that cached version of the page. if one is seeing that page,after loading the page it must go on the log in page

#4
[eluser]boltsabre[/eluser]
You could try looking at the documentation

Session Library

To check if a session variable exists just do this:

Code:
if(!isset($this->session->userdata('userId'))){
   //whatever you want to do, i.e redirect to you login controller
}

#5
[eluser]Aziz Chouhan[/eluser]
thanks for this suggestion.
but i really did so very first moment,but nothing could affect my problem.
ok thanks for suggestion.

#6
[eluser]boltsabre[/eluser]
Hmmm, sorry we couldn't help.

To the best of my knowledge, when a user clicks on the 'back' button either on the screen, or if they have a fancy mouse with a back button and they press it, the page will reload - it does not pull the page from a cache, but will actually pull the file from the server again, thus running all js and php (or whatever) scripts again.

So... if, and correct me if I'm wrong, in your situation you want to check if a user is logged in, even if they click the back button, after they have logged out. Well, any page that can only be accessed whilst logged in should check for a 'logged in' session variable. Best to put it in a helper, and just call it in every controller function that requires it (place it up the top, it should run before any other of that controllers code to prevent issues). It would look something like this:

Code:
// this is your helper function
public function checkLoggedInStatus(){
   if(!isset($this->session->userdata('userId'))){
      // session variable NOT set, user is NOT logged in.
      redirect ('myUserController/login');
   }
}

// and just call it in your controllers like this
public function thisIsAControllerYouMustBeLoggedInToView(){
  // load your helper (well duh)
   $this->load->helper('loggedInHelper');
   $check = checkLoggedInStatus();
   // if user not logged in helper function redirects them to myUserController/login, else
   // continue with this controller and its intended purpose

   // rest of controller code here

And that's it... if a user isn't logged in they get redirected to the login page. Please let us know if that does/does not fix your problem.

#7
[eluser]Mirge[/eluser]
[quote author="Aziz Chouhan" date="1310133508"]but i don't want to see that cached version of the page. if one is seeing that page,after loading the page it must go on the log in page[/quote]

You have no control over how their browser behaves in that regard.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.