How to build in 'maintenance mode' in Codeigniter?

前端 未结 6 1465
醉酒成梦
醉酒成梦 2020-12-15 00:20

I\'m using latest codeigniter and I need to create a flag (ideally in the config) when turned to \'true\', all pages display a \'maintenance mode\' message instead of execut

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-15 00:34

    Here my solution, works fine for me:

    The below will call maintanance.php immediately, so you can go ahead and break your CI code without the world seeing it.

    Also allow you to add you own ip address so that you can still access the site for testing etc.

    In index.php add at top:

    $maintenance = false; ## set to true to enable
    
    if ($maintenance)
    {
        if (isset( $_SERVER['REMOTE_ADDR']) and $_SERVER['REMOTE_ADDR'] == 'your_ip')
        {
            ##do nothing
        } else
        {
    
            error_reporting(E_ALL);
            ini_set('display_errors', 1); ## to debug your maintenance view
    
            require_once 'maintenance.php'; ## call view
            return;
            exit();
    
        }
    }
    

    Add file Maintanance.php in same folder as index.php (or update path above):

    
    
    
        
            
            Maintenance
    
            
        
    
        
    
            
    
            

    Sorry for the inconvenience while we are upgrading.

    Please revisit shortly

提交回复
热议问题