ALite CMS 51.4
Language: 
ALite CMS

Articles

Blocking connections

04.10.2026 14:22  rating: 75  author: ALite CMS 

You can block unwanted connections in the system settings (by IP and USER_AGENT), in the htaccess file, and via the hook alc_hook_user_blocked.

Using the hook alc_hook_user_blocked can be blocked using any available pararameters. For example, by request parameters.

alc_common_add_hook('alc_hook_user_blocked', 'my_user_blocked');
function my_user_blocked(&$ubiu) {
   // if the user is already blocked by system settings, then skip
    if (is_array($ubiu) and count($ubiu) and array_key_exists('cause', $ubiu) and $ubiu['cause']) {
        return;
    }
   // array of forbidden paths in the request
    $arr = array('/.git', '/.evn');
    $q = alc_common_strtolower($_SERVER['REQUEST_URI']);
    foreach ($arr as $v) {
        if ($v and alc_common_stripos($q, $v) !== false) {
            // we indicate the reason for the blocking, it is mandatory
            $ubiu['cause'] = 'bad query';
            // we specify a control value for blocking, optional
            $ubiu['control_value'] = $v;
            return;
        }
    }
}

Tags: #Hooks
RSS  RSS