PHPCMS V9 增加关闭网站功能

2020-02-21 2154

\phpcms\modules\admin\templates\setting.tpl.php:

在代码
<div id="div_setting_1" class="contentList pad-10">
<table width="100%"  class="table_form">

后面另起一行,添加代码:

<tr>
    <th width="120">网站状态</th>
    <td class="y-bg"><input name="setconfig[website_is_closed]" value="2" type="radio"<?php echo ($website_is_closed==2) ? ' checked="checked"' : '';?> /> 仅供管理员访问<!-- Only admin -->&nbsp;&nbsp;&nbsp;&nbsp;
    <input name="setconfig[website_is_closed]" value="1" type="radio"<?php echo ($website_is_closed==1) ? ' checked="checked"' : '';?> /> 禁止所有人访问<!-- Ban all -->&nbsp;&nbsp;&nbsp;&nbsp;
    <input name="setconfig[website_is_closed]" value="0" type="radio" <?php echo (!$website_is_closed) ? ' checked="checked"' : '';?> /> 允许所有人访问<!-- Open to all --></td>
  </tr>
  <tr>
    <th width="120">关站提示信息</th>
    <td class="y-bg"><textarea rows="2" cols="20" id="tips" style="height:40px; width:80%" name="setconfig[off_site_because]"><?php echo htmlspecialchars($off_site_because);?></textarea>&nbsp;&nbsp;&nbsp;&nbsp;支持HTML标签</td>
  </tr>


\phpcms\modules\admin\functions\global.func.php:
在set_config()函数中,在代码
if(in_array($k,array(

后面添加:
'website_is_closed','off_site_because',

\phpcms\modules\admin\setting.php:

在代码
set_config($_POST['setconfig']);

前面另起一行,添加代码:

if(!empty($_POST['setconfig']['website_is_closed'])){
    $str='<!DOCTYPE HTML><html><head>< http-equiv="Content-Type" content="text/html; charset='.CHARSET.'" />< http-equiv="refresh" content="1;url=index.php" />< ></ ></head><body></body></html>';
    if(pc_ ::load_config('system','lock_ex')){ 
        file_put_contents(PHPCMS_PATH.'index.html', $str, LOCK_EX);
    }else{
        file_put_contents(PHPCMS_PATH.'index.html', $str);
    }
}
unset($str);


\index.php:

在代码
pc_ ::creat_app();

前面另起一行,添加代码:

switch(pc_ ::load_config('system','website_is_closed')){
    case '2': //仅允许后台用户访问
        $session_storage = 'session_'.pc_ ::load_config('system','session_storage');
        pc_ ::load_sys_class($session_storage);
        if(!empty($_SESSION['userid']) && !empty($_SESSION['roleid'])){
            break;
        }
    case '1': //禁止所有人访问
        if($_GET['m']=='admin'){
            break; //可以访问后台
        }
        if(pc_ ::load_config('system','off_site_because')!==''){
            echo nl2br(pc_ ::load_config('system','off_site_because'));
        }
        exit;
    default: //向所有公开
}


\caches\configs\system.php:
在文件末尾的代码
);
?>

前面添加:
'website_is_closed' => '0',
'off_site_because' => '',

完毕!

以上就是PHPCMS V9 增加关闭网站功能的详细内容,更多请关注php知识-学习天地 www.lxywzjs.com其它相关文章!

分享至:

分享到QQ空间 分享到朋友社区 新浪微博分享

栏目地图