![]() |
Check if session is started otherwise redirect to home with message - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Check if session is started otherwise redirect to home with message (/showthread.php?tid=50939) |
Check if session is started otherwise redirect to home with message - El Forum - 04-14-2012 [eluser]ReyPM[/eluser] Hi, I'm trying to check if users has logged in in my site and if not then redirect it to login page but I need this across all the function in my controllers. I don't want to repeat the code so I think in this: Code: function __construct() { Cheers Check if session is started otherwise redirect to home with message - El Forum - 04-14-2012 [eluser]Samus[/eluser] [quote author="ReyPM" date="1334410776"]Hi, I'm trying to check if users has logged in in my site and if not then redirect it to login page but I need this across all the function in my controllers. I don't want to repeat the code so I think in this: Code: function __construct() { Cheers[/quote] because you're not actually blocking access. All I can see you doing is setting flashdata. Why don't you redirect them? Code: if(!$this->session->userdata('session_id')) { Check if session is started otherwise redirect to home with message - El Forum - 04-14-2012 [eluser]ReyPM[/eluser] Didn't work I can still accessing to any URL even if user isn't logged in |