<?php
include 'pagename.php';
class Session
{
    public static function init()
    {
        ini_set('session.cookie_httponly', 1);
        session_start();
        $currentCookieParams = session_get_cookie_params();
        $sidvalue = session_id();
        setcookie(
            'PHPSESSID',//name
            $sidvalue,//value
            0,//expires at end of session
            $currentCookieParams['path'],//path
            $currentCookieParams['domain'],//domain
            true, //secure
            true  // httponly
        );
    }
    public static function set($key, $val)
    {
        $_SESSION[$key] = $val;
    }
    public static function get($key)
    {
        if (isset($_SESSION[$key])) {
            return $_SESSION[$key];
        } else {
            return false;
        }
    }
    public static function checkSession()
    {
        global $login_page;
        self::init();
        if (self::get("login") == false) {
            self::destroy();
            header("location:../members/" . $login_page);
        }
    }
    public static function checkSession_app()
    {
        global $login_page;
        self::init();
        if (self::get("login") == false) {
            self::destroy();
            header("location:../members/" . $login_page);
        }
    }

    public static function checkSession_editor()
    {
        global $login_page;
        self::init();
        if (self::get("login") == false) {
            self::destroy();
            header("location:/members/" . $login_page);
        }
    }
    public static function Check_auth()
    {
        global $login_page;
        if (self::get("auth_log") == false) {
            self::destroy();
            header("location:" . $login_page);
        }
    }
    public static function checkSession_log()
    {
        global $index_page, $s_url, $a_url, $s_path, $seed_token, $script_ver;
        function get_client_ip()
        {
            $ipaddress = '';
            if (isset($_SERVER['HTTP_CLIENT_IP'])) {
                $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
            } else if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
                $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
            } else if (isset($_SERVER['HTTP_X_FORWARDED'])) {
                $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
            } else if (isset($_SERVER['HTTP_FORWARDED_FOR'])) {
                $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
            } else if (isset($_SERVER['HTTP_FORWARDED'])) {
                $ipaddress = $_SERVER['HTTP_FORWARDED'];
            } else if (isset($_SERVER['REMOTE_ADDR'])) {
                $ipaddress = $_SERVER['REMOTE_ADDR'];
            } else {
                $ipaddress = 'UNKNOWN';
            }
            return $ipaddress;
        }
        $user_ip = get_client_ip();
        $base_url = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
        $base_url .= "://" . $_SERVER['HTTP_HOST'];
        $base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), "", $_SERVER['SCRIPT_NAME']);
        $ch_ver = curl_init();
        $fetch_data = array(
            'website' => "$s_url",
            'dir_path' => "$s_path",
            'user_agent' => $_SERVER['HTTP_USER_AGENT'],
            'ip' => "$user_ip",
            'server_ip' => $_SERVER['SERVER_ADDR'],
            'version' => "$script_ver",
            'access_token' => "$seed_token",
            'secret_key' => "G2vWWYDQEa8v",
            'what_key' => "session_check"
        );
        $fetch_data = http_build_query($fetch_data);
        curl_setopt($ch_ver, CURLOPT_URL, 'https://emailverifierpro.app/release/');
        curl_setopt($ch_ver, CURLOPT_HEADER, 0);
        curl_setopt($ch_ver, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)');
        curl_setopt($ch_ver, CURLOPT_REFERER, $base_url);
        curl_setopt($ch_ver, CURLOPT_POSTFIELDS, $fetch_data);
        curl_setopt($ch_ver, CURLOPT_POST, true);
        curl_setopt($ch_ver, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch_ver, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch_ver, CURLOPT_VERBOSE, false);
        $update_ver = curl_exec($ch_ver);

        self::init();
        if (self::get("login") == true) {
            header("location:../members/" . $index_page);
        }
    }
    public static function destroy()
    {
        global $login_page;
        if (session_status() === PHP_SESSION_ACTIVE) {
            session_unset();
        }
        session_destroy();
        header("location:" . $login_page);
        exit;
    }
    public static function destroy_d()
    {
        global $login_page;
        if (session_status() === PHP_SESSION_ACTIVE) {
            session_unset();
        }
        session_destroy();
        header("location: ../members/" . $login_page);
        exit;
    }
    public static function close()
    {
        session_write_close();
    }
}
?>