Таинственный редирект PHP

При каких условиях может не срабатывать условие?

Как видно на скринах, первая проверка дает true, а вторая false. В итоге все должно быть ок, но проблема в том, ЧТО РЕДИРЕКТ ПОСЛЕ 3 УСЛОВИЯ РАБОТАЕТ! ЧТО ЭТО ЗА МАГИЯ? Функция редиректа:

static function redirect($url)
{
    if(str_replace('http://site.ru/', '/', $_SERVER["HTTP_REFERER"]) != $url){
        header("Location: {$url}");
        exit();
    }
}

Просили скинуть больше кода, поэтому вот:

protected $currentPage = [];

public function __construct()
{
    $this->renderCurrentPage();
    $GLOBALS['CURRENT_PAGE'] = $this->currentPage;
    $this->controllerManager();
}

function renderCurrentPage()
{
    $current_url = trim($_SERVER['REQUEST_URI'],'/');
    $current_url = explode('/', strtok($current_url, '?'));

    $cm = [];
    $keys = [];
    foreach ($current_url as $key => $value){
        if(!is_numeric($value)){
            array_push($cm, $value);
        }
        else {
            array_push($keys, $value);
        }
    }

    $cm = HELPER::clearArray($cm);

    if(isset($cm[0])){
        if(isset($cm[1])){
            $cm['controller'] = $cm[0];
            unset($cm[0]);
            $cm['method'] = $cm[1];
            unset($cm[1]);
        }
        else{
            $cm['method'] = $cm[0];
            $cm['controller'] = 'main';
            unset($cm[0]);
        }
    }
    else{
        $cm = false;
    }

    $keys = HELPER::keyDebugging($keys);

    if ($cm == false) {
        $this->currentPage = [
            'ajax' => false,
            'controller' => 'Main',
            'method' => 'Index',
            'access' => 0,
            'auth' => false,
            'meta_value' => []
        ];
    } else {
        $properties = HELPER::getProperties($cm['controller'], $cm['method']);

        var_dump("asd", count($properties)>0);
        if (count($properties)>0) {
            if (isset($keys[0]))
                $properties['meta_value'] = HELPER::renderMetaValue($properties['meta_value'], $keys);
            else $properties['meta_value'] = [];

            if (!FIREWALL::accessAllowed($properties['access'], $properties['auth'])) {
                VIEW::redirect('/error404');
            }
            else{
                $this->currentPage = $properties;
            }
            var_dump("1", !FIREWALL::accessAllowed($properties['access'], $properties['auth']));
        }else{
            var_dump("123", $properties);
            VIEW::redirect('/error404');
        }
    }
}

function controllerManager()
{
    $controller = CONTROLLERS . ucfirst($this->currentPage['controller']);
    $method = ucfirst($this->currentPage['method']);

    if (file_exists($controller . '.php')) {
        $controller = HELPER::renderPath(CONTROLLERS) . ucfirst($this->currentPage['controller']);
        if (class_exists($controller)) {
            $controller = new $controller();
            if (method_exists($controller, $method)) {
                $controller->$method();
            }
        }
    }

}

class FIREWALL { static function accessAllowed($acc = 0, $auth = false){

    $ac = self::access($acc);
    $au = self::authorized($auth);

    return ($ac && $au);
}

static function authorized($auth = false){

    $au = (int)$auth;
    $sa = (int)$_SESSION['AUTH'];

    if ($au <= $_SESSION['AUTH']) {
        return true;
    } else return false;
}

static function access($access = 0){
    $acc = $_SESSION['ACCESS'];
    $data = $access;

    $acc = (int)$acc;
    $data = (int)$data;

    if ($acc >= $data) {
        return true;
    } else return false;
}

}

static function clearArray($array = [])
{
    $arr = [];
    if (count($array) > 0) {
        foreach ($array as $key => $value) {
            if ($value == null || $value == '' || (is_array($value) && count($value) <= 0))
                unset($array[$key]);
            else $arr[$key] = $value;
        }
        return $arr;
    }
    return false;
}

static function keyDebugging($array = [])
{
    $arr = [];
    if (count($array) > 0) {
        foreach ($array as $key => $value) {
            if ($value == null || $value == '' || (is_array($value) && count($value) <= 0))
                unset($array[$key]);
            else array_push($arr, $value);
        }
        return $arr;
    }
    return false;
}

static function renderMetaValue($meta_key = [], $meta_value = [])
{
    $arr = [];

    if ($meta_value == false)
        return [];

    if (count($meta_key) > 0 && count($meta_value) > 0) {
        foreach ($meta_key as $key => $value) {
            if (key_exists($key, $meta_value))
                $arr[$value] = $meta_value[$key];
            else $arr[$value] = null;
        }
        return $arr;
    }
    return false;
}

static function getProperties($controller = '', $method = '')
{
    $sql = "SELECT `PROPERTIES` FROM `pages` WHERE (JSON_EXTRACT(`PROPERTIES`, \"$.controller\") = :controller) AND (JSON_EXTRACT(`PROPERTIES`, \"$.method\") = :method) LIMIT 1";
    $opt = ['controller' => strtolower($controller), 'method' => strtolower($method)];

    $result = DATABASE::RequestAsColumn($sql, $opt);

    $result = json_decode($result, true);

    if (is_array($result))
        return $result;
    else return [];
}

static function getMetaKey($controller = '', $method = '')
{
    $sql = "SELECT JSON_EXTRACT(`PROPERTIES`, \"$.meta_value\") FROM `pages` WHERE (JSON_EXTRACT(`PROPERTIES`, \"$.controller\") = :controller) AND (JSON_EXTRACT(`PROPERTIES`, \"$.method\") = :method) LIMIT 1";
    $opt = ['controller' => strtolower($controller), 'method' => strtolower($method)];

    $result = DATABASE::RequestAsColumn($sql, $opt);
    $result = json_decode($result, true);

    if (is_array($result))
        return $result;
    else return [];
}

static function renderPath($path = '')
{
    $arr = [];
    if ($path != '') {
        $arr = explode('/', $path);
        $arr = self::clearArray($arr);
        $arr = self::keyDebugging($arr);

        $return = '';
        foreach ($arr as $key => $value) {
            $return .= $value . '\\';
        }
        return $return;
    } else return false;
}

static function getPageProperties($key = '')
{
    if (isset($GLOBALS['CURRENT_PAGE'][$key]))
        return $GLOBALS['CURRENT_PAGE'][$key];
    else return false;
}

static function renderMetaKeys($string = '', $prefix = 'key')
{
    $result = "";
    $arr = explode(', ', $string);
    $arr = self::clearArray($arr);

    $result = ['values' => []];

    $json = "JSON_ARRAY(";
    foreach ($arr as $key => $value) {
        if (key_exists($key + 1, $arr))
            $json .= ":{$prefix}_{$key}, ";
        else $json .= ":{$prefix}_{$key}";

        $result['values']["{$prefix}_{$key}"] = $value;
    }
    $json .= ")";
    $result['json'] = $json;

    return $result;
}

static function getMetaValue($key = '')
{
    if (isset($GLOBALS['CURRENT_PAGE']['meta_value'][$key]))
        return $GLOBALS['CURRENT_PAGE']['meta_value'][$key];
    else return false;
}

static function arrayFull($array = [], $keys = '')
{

    $arr = str_replace(' ', '', $keys);
    $arr = explode(',', $arr);
    $arr = self::clearArray($arr);
    $arr = self::keyDebugging($arr);

    foreach ($arr as $key => $value) {
        if (!isset($array[$value]))
            return false;
    }
    return true;
}

Скрин того, что творится, если скрыть var_dump'ы


Ответы (0 шт):