Location: PHPKode > projects > Entier Studio > entierstudio/framework/usersession.php
<?php
/**
 * Entier Studio
 *
 * LICENSE
 *
 *	Copyright 2006 Entier Studio team.
 *
 *	Licensed under the Apache License, Version 2.0 (the "License");
 *	you may not use this file except in compliance with the License.
 *	You may obtain a copy of the License at
 *
 *		http://www.apache.org/licenses/LICENSE-2.0
 *
 *	Unless required by applicable law or agreed to in writing, software
 *	distributed under the License is distributed on an "AS IS" BASIS,
 *	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *	See the License for the specific language governing permissions and
 *	limitations under the License.
 *
 * @package    entier.framework
 * @copyright  Copyright (c) 2006 Entier Studio team. All rights reserved.
 * @version	   $Id: usersession.php 81 2008-01-17 23:08:21Z yannromefort $
 */
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefUserSession")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefUserSession", "1");
    //
    define(PROXY_USER_SERIALIZATION_NONE, 0);
    define(PROXY_USER_SERIALIZATION_SESSION, 1);
    define(PROXY_USER_SERIALIZATION_PRIVACY, 2);
    //
    define(AUTH_NONE_BASED, 0);
    define(AUTH_HTTP_BASED, 1);
    define(AUTH_FORM_BASED, 2);
    //-------------------------------------------------------------------------
    //	Class
    class UserSession {
        //---------------------------------------------------------------------
        //	Attributes
        
        /**
         * Permanent user cookie name
         *
         * @var	string
         * @see	UserSession
         * @see	checkUserSerialization
         */
        var $m_PrivacyName = ""; //
        
        /**
         * Session user cookie name
         *
         * @var	string
         * @see	UserSession
         * @see	checkUserSerialization
         */
        var $m_SessionName = ""; //
        
        /**
         *
         * @var	string
         * @see	CheckUserRedirection
         */
        var $m_GenerateID = ""; //
        //---------------------------------------------------------------------
        //	Constructor
        
        /**
         * UserSession constructor.
         *
         * @param	string	user cookie name
         * @param	array	session cookie name
         * @access	public
         */
        function UserSession($privacyName = "", $sessionName = "") {
            //
            $this->m_PrivacyName = $privacyName;
            $this->m_SessionName = $sessionName;
        }
        //---------------------------------------------------------------------
        //	Properties
        
        /**
         *
         * @param	string
         */
        function UserAuthentification($text = "") {
            //
            header("WWW-Authenticate: Basic realm=\"My Realm\"");
            header("HTTP/1.0 401 Unauthorized");
            print "$text";
            //
            return (headers_sent());
        }
        /**
         *
         * @param	string
         */
        function UserRedirection($page = "") {
            //
            header("Location: $page");
            //
            exit(headers_sent());
        }
        //---------------------------------------------------------------------
        //	Methods
        
        /**
         *
         * @param	string	user cookie name
         */
        function checkUserSerialization($user = 0) {
            //
            @include_once (FRAMEWORK_DIR . "httpsession.php");
            //
            $session = new HttpSession();
            if ($session->get_session_id($this->m_SessionName) == false) return (PROXY_USER_SERIALIZATION_NONE);
            if ($session->get_privacy_id($this->m_PrivacyName) == false) return (PROXY_USER_SERIALIZATION_SESSION);
            //
            if (!empty($user) && (@md5($user) == $session->m_PrivacyID)) return (PROXY_USER_SERIALIZATION_PRIVACY);
            //
            return (PROXY_USER_SERIALIZATION_NONE);
        }
        /**
         *
         */
        function CheckUserRedirection($user = 0, $page = "") {
            //
            global $SERVER_NAME;
            global $SERVER_PORT;
            global $PHP_AUTH_USER;
            global $PHP_AUTH_PW;
            global $PHP_SELF;
            //
            @include_once (FRAMEWORK_DIR . "class.cache.manager.php");
            //
            $source = new DataSource($SERVER_NAME, $SERVER_PORT, (empty($user) ? $PHP_AUTH_USER : $user) , (empty($user) ? $PHP_AUTH_PW : "") , $PHP_SELF);
            $this->m_GenerateID = $source->UniqueId($page);
            //
            $cache = new CacheManager("c:/temp/html.cache.db3", "db3");
            if ($cache->GetCacheEntry($source, $page) == true) return ($this->UserRedirection($page));
            //
            return (false);
        }
        /**
         *
         */
        function CheckUserAuthorization($user = 0, $page = "") {
        }
        /**
         *
         */
        function CheckUserAuthentification($name = "", $pass = "") {
            //
            global $PHP_AUTH_USER;
            global $PHP_AUTH_PW;
            //
            if (!isset($PHP_AUTH_USER) || (!empty($name) && ($PHP_AUTH_USER != $name))) return (false);
            //
            if (!isset($PHP_AUTH_PW) || (!empty($pass) && ($PHP_AUTH_PW != $pass))) return (false);
            //
            return (true);
        }
    };
    //	Class
    //-------------------------------------------------------------------------
    
}
//	namespace
//-----------------------------------------------------------------------------
?>
Return current item: Entier Studio