Welcome Guest, Not a member yet? Register   Sign In
Login check
#7

[eluser]Werner85[/eluser]
I now solved it using autoloading. Just like I had in mind.
I only have to add the pages to the exclude array to prevent them being checked. At this moment it's only the login page, but more might be coming...

Maybe I will use your code in the future, but at this moment it's not needed. Thanks for your help!

Code:
<?php
if (!defined("BASEPATH")) {
    exit("No direct script access allowed");
}

class CheckLogin {
    function __construct() {
        $ci =& get_instance();
        
        // Pages to exclude from login check
        $excluded = array("login");
        
        if (!in_array($ci->uri->segment(1), $excluded)) {
            $is_logged_in = $ci->session->userdata("is_logged_in");
            
            if (!isset($is_logged_in) || $is_logged_in != TRUE) {
                redirect("login");
            }
        }
    }
}
?>


Messages In This Thread
Login check - by El Forum - 04-16-2010, 04:10 AM
Login check - by El Forum - 04-16-2010, 04:21 AM
Login check - by El Forum - 04-16-2010, 04:24 AM
Login check - by El Forum - 04-16-2010, 04:30 AM
Login check - by El Forum - 04-16-2010, 06:28 AM
Login check - by El Forum - 04-16-2010, 06:33 AM
Login check - by El Forum - 04-16-2010, 07:12 AM



Theme © iAndrew 2016 - Forum software by © MyBB