    <?php
    function getcookiename($key = '')
    {
        $_prefix = 'june';
        $array = array(
            'user' => $_prefix . '_user',
            'userid' => $_prefix . '_userid',
            'usertype' => $_prefix . '_usertype',
            'userphoto' => $_prefix . '_userphoto',
            'usertype_name' => $_prefix . '_usertype_name',
            'userlastlogin' => $_prefix . '_userlastlogin',
            'userlang' => $_prefix . '_userlang',
        );
        if (isset($array[$key])) return $array[$key];
        else return NULL;
    }

    function getCookie($key = '')
    {
        if ($key) {
            $cookie_key = getcookiename($key);
            if (isset($cookie_key)) return @$_COOKIE[$cookie_key];
            else return NULL;
        }
    }

    function checklogin()
    {
        if (getCookie('userid') == "" && getCookie('user') == "" && getCookie('usertype_id') == "") {
            echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">';
            echo "<script> window.location.href='" . base_url() . "login'  </script>";
        } else {

            foreach ($_COOKIE as $key => $value) {
                $data[$key] = $value;
            }

            if (isset($_SERVER['HTTP_COOKIE'])) {
                $cookies = explode(';', $_SERVER['HTTP_COOKIE']);
                foreach ($cookies as $cookie) {
                    $parts = explode('=', $cookie);
                    $name = trim($parts[0]);
                    setcookie($name, '', time() - (COOKIE_TIME) * 2, "/");
                }
            }

            if ($data[getcookiename('user')] != "")
                setcookie(getcookiename('user'), $data[getcookiename('user')], time() + COOKIE_TIME, '/');
            if ($data[getcookiename('userid')] != "")
                setcookie(getcookiename('userid'), $data[getcookiename('userid')], time() + COOKIE_TIME, '/');
            if (isset($data[getcookiename('userlastlogin')]) && $data[getcookiename('userlastlogin')] != "")
                setcookie(getcookiename('userlastlogin'), $data[getcookiename('userlastlogin')], time() + COOKIE_TIME, '/');
            if ($data[getcookiename('userlang')] != "")
                setcookie(getcookiename('userlang'), $data[getcookiename('userlang')], time() + COOKIE_TIME, '/');
            return true;
        }
    }

    function is_signed_in()
    {
        if (getCookie("userid") != "")
            return true;
        else
            return false;
    }

    function pre($array = '')
    {

        echo '<pre>';
        print_r($array);
        echo '</pre>';

    }

    function set_lang($lang_id = '')
    {
        setcookie(getcookiename('userlang'), $lang_id, time() + time() + COOKIE_TIME, '/');
    }

    function get_lang()
    {
        if (@$_COOKIE[getcookiename('userlang')] == NULL) {
            set_lang(1);
            return 1;
        } else {
            return @$_COOKIE[getcookiename('userlang')];
        }
    }

    function _redirect_message($hash)
    {

        $HTTP_REFERER = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;

        if ($HTTP_REFERER === null)
            die("Invalid Referer. Output Message: {$hash}");

        header("Location: {$HTTP_REFERER}{$hash}");
        exit;
    }

    ?>
