Welcome Guest, Not a member yet? Register   Sign In
How can I lock down my entire site?
#1

[eluser]Aquillyne[/eluser]
My site has an admin area accessible by logging in. Inside the admin area I want a button that reads "Lock". If the admin clicks on this, every page request on the site delivers a "Site is locked down" message rather than loading (apart from the pages in the admin area, obviously). This continues until the admin clicks "Unlock".

What would be the simplest way of achieving this behaviour? I prefigure some Router extensions? Or maybe a simple hook?
#2

[eluser]Colin Williams[/eluser]
Sounds like if you had a pre-controller hook, you could check a variable stored in a database table or even flat-text file and then serve up the "LOCKED!!" (don't forget the exclamation marks) page accordingly.
#3

[eluser]Michael Wales[/eluser]
A hook, or extending the Controller class, would be the simplest.
#4

[eluser]Aquillyne[/eluser]
This works:

post-controller-constructor

Code:
class Lock
{
    
    var $locked = TRUE;
    var $CI;
    
    function check()
    {
        $this->CI =& get_instance();
        
        if ($this->locked)
        {
            $data["PageTitle"] = "LOCKED!!";
            $data["Content"] = "LOCKED!!";

            $this->CI->load->view("locked", $data);
            $this->CI->output->_display();
            die();
        }
    }
    
}

Can anyone say if I'm doing anything a little clumsily here? Or is this fine?

The problem remains: how to alter whether the site is locked via the button in the admin area...
#5

[eluser]Colin Williams[/eluser]
Hook looks alright. Nice and simple.

Quote:The problem remains: how to alter whether the site is locked via the button in the admin area…

Again, save a var in a database table or in a flat text file that you check in your hook. Are you familiar with using databases or manipulating files?
#6

[eluser]Aquillyne[/eluser]
[quote author="Colin Williams" date="1216637729"]Hook looks alright. Nice and simple.

Quote:The problem remains: how to alter whether the site is locked via the button in the admin area…

Again, save a var in a database table or in a flat text file that you check in your hook. Are you familiar with using databases or manipulating files?[/quote]

Yes. I think I'll go for a text file, otherwise every page on my site will initiate a database connection which may slow things down. Thanks for the help!
#7

[eluser]Colin Williams[/eluser]
You don't even need to write data to a file, just check for the existence of one. Then, all your admin function does is create/destroy the file as needed.




Theme © iAndrew 2016 - Forum software by © MyBB