php - 如何在 Codeigniter 中构建 'maintenance mode'?

标签 php codeigniter

我使用的是最新的 codeigniter,我需要创建一个标志(最好在配置中),当它变为“true”时,所有页面都会显示“维护模式”消息,而不是执行它们的 Controller 代码。

执行此操作的最佳/最简单做法是什么?

最佳答案

这是我的解决方案,对我来说效果很好:

下面会立即调用 maintanance.php,这样你就可以在不让外界看到的情况下继续破解你的 CI 代码。

还允许您添加自己的 IP 地址,以便您仍然可以访问该站点进行测试等。

在 index.php 顶部添加:

$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();

    }
}

在与 index.php 相同的文件夹中添加文件 Maintanance.php(或上面的更新路径):

<!DOCTYPE html>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Maintenance</title>

        <style>
            body {
                width:500px;
                margin:0 auto;
                text-align: center;
                color:blue;
            }
        </style>
    </head>

    <body>

        <img src="images/home_page_logo.png">

        <h1><p>Sorry for the inconvenience while we are upgrading. </p>
            <p>Please revisit shortly</p>
        </h1>
        <div></div>

        <img src="images/under-maintenance.gif"   >

    </body>
</html>
<?php
header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
header('Retry-After: 3600');
?>

关于php - 如何在 Codeigniter 中构建 'maintenance mode'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15572568/

相关文章:

php - 在查询中放置 IF (MYSQL)

php - 警告 : mysql_fetch_array(): supplied argument is not a valid MySQL result resource

php - 表关系问题 - 从第二个表收集信息

php - CodeIgniter 多数据库持久连接?

php - 使用 order by 和 limit CodeIgniter 在 10 个结果中选择 5 个随机结果?

php - 连接表时字段列表中的列不明确 codeigniter

codeigniter - 在 MongoDB 查询中组合 AND 和 OR

php - Mysql数据库表列值增量不起作用

mysql - 使用 jQuery AJAX 请求 CodeIgniter 在不刷新页面的情况下从 Controller 显示数据库中的数据到 View

java - 用于电子商务的 PHP 或 Java