You can disable the specified IP address or IP address segment from accessing the foreground, and allow the specified IP address or IP address segment to log on to the background to enhance website security. IP segments are represented by "*". Multiple IP addresses are separated by commas (,), and their priority ranges are from left to right. The program version is ecshop2.7.3. For earlier versions, manually upgrade the program.
The implementation steps are as follows:
1. Execute SQL statements in the background, add the required fields, and the default IP addresses. You can modify them by yourself. For example:
INSERT INTO ecs_shop_config (id, parent_id, code, type, store_range, store_dir, value, sort_order) VALUES(10, 0, ‘ip_limit‘, ‘group‘, ‘‘, ‘‘, ‘‘, 1),(1001, 10, ‘front_block‘, ‘select‘, ‘1,0‘, ‘‘, ‘0‘, 1),(1002, 10, ‘front_block_ip‘, ‘text‘, ‘‘, ‘‘, ‘58.60.68.134,61.135.169.*,125.39.127.*‘, 1),(1003, 10, ‘back_permit‘, ‘select‘, ‘1,0‘, ‘‘, ‘0‘, 1),(1004, 10, ‘back_permit_ip‘, ‘text‘, ‘‘, ‘‘, ‘174.36.160.*,174.36.161.155‘, 1);
2. Add the content at the end of the website/website des/lib_common.php File
/** * 检查客户端IP是否在名单中 * @param string $ip_list IP配置字符串 * @param string $real_ip 客户端IP * @return boolean $flag 返回布尔值 */function checkIP($ip_list, $real_ip, $flag){$list = explode(‘,‘, $ip_list);foreach($list as $ipStr){//从右向左检查IP字符串,如果不含星号,则不是IP段。if(strpos($ipStr, ‘*‘) == false) {if($ipStr == real_ip()){ $flag = true;return $flag;}}else{//如果星号之前的IP段字符串是客户端IP的子串$ipStr = substr($ipStr, 0, strpos($ipStr, ‘*‘)-1);if(strpos($real_ip, $ipStr) !== false){$flag = true;return $flag;}}}return $flag; //不在名单中}
3. Add at the end of the website/website des/init. php file
/* 前台IP限制 */if($_CFG[‘front_block‘] == ‘1‘){$flag = false;$flag = checkIP($_CFG[‘back_permit_ip‘], real_ip(), $flag);if($flag){ echo $_LANG[‘access_deny‘]; exit;}}
4. Add
/* 后台IP限制 */if($_CFG[‘back_permit‘] == ‘1‘){$flag = false;$flag = checkIP($_CFG[‘back_permit_ip‘], real_ip(), $flag);if(!$flag){ echo $_LANG[‘access_deny‘]; exit;}}
5. Add the following content to the website/languages/zh_cn/admin/shop_config.php:
/* 访问限制 */$_LANG[‘cfg_name‘][‘ip_limit‘] = ‘访问限制‘;$_LANG[‘cfg_name‘][‘front_block‘] = ‘是否开启前台IP限制‘;$_LANG[‘cfg_range‘][‘front_block‘][0] = ‘关闭‘;$_LANG[‘cfg_range‘][‘front_block‘][1] = ‘开启‘;$_LANG[‘cfg_name‘][‘front_block_ip‘] = ‘前台IP黑名单‘;$_LANG[‘cfg_desc‘][‘front_block_ip‘] = ‘IP段用*表示,多个地址用半角逗号分隔,优先级自左向右。‘;$_LANG[‘cfg_name‘][‘back_permit‘] = ‘是否开启后台IP限制‘;$_LANG[‘cfg_range‘][‘back_permit‘][0] = ‘关闭‘;$_LANG[‘cfg_range‘][‘back_permit‘][1] = ‘开启‘;$_LANG[‘cfg_name‘][‘back_permit_ip‘] = ‘后台IP白名单‘;$_LANG[‘cfg_desc‘][‘back_permit_ip‘] = ‘IP段用*表示,多个地址用半角逗号分隔,优先级自左向右。‘;
6. add them to the mall/ages/zh_cn/common. php
/* 访问限制 */$_LANG[‘access_deny‘] = ‘对不起,您的IP已被列入黑名单,请联系管理员。‘;
7. Add/ages/zh_cn/admin/common. php
/* 访问限制 */$_LANG[‘access_deny‘] = ‘对不起,您的IP不在白名单中,请联系管理员。‘;
Success!
Note: The text of the Language Pack can be adjusted according to your wishes. The text displayed here only indicates the approximate meaning. I am studying the status, mainly using learning. Any problems caused by this Code have nothing to do with me. (I just recorded my notes here ).
Limited IP address access in front and back of mall