CodeIgniter Forums
Autometic redirect on login page after session expire - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12)
+--- Thread: Autometic redirect on login page after session expire (/showthread.php?tid=66589)

Pages: 1 2


Autometic redirect on login page after session expire - rupamhazra - 11-08-2016

Hi,

I want to add a functionality where after login a user it can automatically redirect login page after a certain time.

Please help.


RE: Autometic redirect on login page after session expire - php_rocs - 11-08-2016

@rupamhazra - I have a few questions. How is your security configured for your application (i.e. does it check users access for every page)? Do you use session variables?


RE: Autometic redirect on login page after session expire - rupamhazra - 11-08-2016

@php_rocs

Yes, i have added session variable and checking the session variable on every page to access also i used cookie for implement "remember me" functionality.Now I want to implement automatic logout after a session.


RE: Autometic redirect on login page after session expire - rupamhazra - 11-09-2016

Hi,

I have added this functionality..

Thanks.


RE: Autometic redirect on login page after session expire - php_rocs - 11-09-2016

This should be straight forward. Where you check you're users access to a page you can incorporate a condition that checks to see if a session variable (one that is set during a successful login) is set. If it is not set then the user is automatically redirected to the login page otherwise continue through to the selected page.


RE: Autometic redirect on login page after session expire - php_rocs - 11-09-2016

As an example. When a user logs in you may set a session variable for userid. This variable is available throughout the usage of the application. if the user's browser does not interact with the web server for the specified session time (which is 24 minutes by default - 1440 seconds), the next time the user tries to refresh or go to another page they will automatically be directed to the login page (which will force them to login again).


RE: Autometic redirect on login page after session expire - php_rocs - 11-09-2016

You can then use the codeigniter redirect function to take you to the login page. Oh, and don't forget to bring in the url helper [$this->load->helper('url');]. Hopefully this helps you.

Here is a documentation link for the codeigniter function redirect. ( http://www.codeigniter.com/user_guide/helpers/url_helper.html?highlight=redirect#redirect )


RE: Autometic redirect on login page after session expire - rupamhazra - 11-09-2016

Thanks, but already done these functionality.


RE: Autometic redirect on login page after session expire - php_rocs - 11-10-2016

(11-09-2016, 09:27 PM)rupamhazra Wrote: Thanks, but already done these functionality.

Did I miss something?  
Are you trying to set a specific time for each login?  
Are you trying to reset the session time for PHP? 
What exactly are you trying to accomplish?


RE: Autometic redirect on login page after session expire - rupamhazra - 11-10-2016

(11-10-2016, 08:55 AM)php_rocs Wrote:
(11-09-2016, 09:27 PM)rupamhazra Wrote: Thanks, but already done these functionality.

Did I miss something?  
Are you trying to set a specific time for each login?  
Are you trying to reset the session time for PHP? 
What exactly are you trying to accomplish?

 Yes i have done those points which you have advised.