Location: PHPKode > projects > Entier Studio > entierstudio/framework/useripaddress.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: useripaddress.php 81 2008-01-17 23:08:21Z yannromefort $
 */
/*
*
* Copyright:
*
* You may use freely this script, class or functions.
* We hope you'll respect the author's intellectual property by
* --- keeping this notice in your source
*     author's URL is: http://www.marc.meurrens.org
* --- setting a link to the URL of these PHP scripts:
*     http://www.cgsa.net/php
* --- dropping a note to the author:
*     hide@address.com
*
*/
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefUserIPAddress")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefUserIPAddress", "1");
    //-------------------------------------------------------------------------
    //	Class
    class UserIPAddress {
        //---------------------------------------------------------------------
        //	Attributes
        //---------------------------------------------------------------------
        //	Constructor
        
        /**
         * UserIPAddress constructor.
         *
         * @param	string	user cookie name
         * @param	array	session cookie name
         * @access	public
         */
        function UserIPAddress() {
            //
            
        }
        //---------------------------------------------------------------------
        //	Methods
        
        /**
         *
         * @param	boolean		resolve lag
         */
        function IPAddress($resolve = false) {
            //
            global $HTTP_VIA, $HTTP_X_COMING_FROM, $HTTP_X_FORWARDED_FOR, $HTTP_X_FORWARDED, $HTTP_COMING_FROM, $HTTP_FORWARDED_FOR, $HTTP_FORWARDED, $REMOTE_ADDR;
            //
            $clientip = "";
            //
            if ($HTTP_X_FORWARDED_FOR)
            // case 1.A: proxy && HTTP_X_FORWARDED_FOR is defined
            $clientip = $HTTP_X_FORWARDED_FOR;
            elseif ($HTTP_X_FORWARDED)
            // case 1.B: proxy && HTTP_X_FORWARDED is defined
            $clientip = $HTTP_X_FORWARDED;
            elseif ($HTTP_FORWARDED_FOR)
            // case 1.C: proxy && HTTP_FORWARDED_FOR is defined
            $clientip = $HTTP_FORWARDED_FOR;
            elseif ($HTTP_FORWARDED)
            // case 1.D: proxy && HTTP_FORWARDED is defined
            $clientip = $HTTP_FORWARDED;
            elseif ($HTTP_VIA)
            // case 2:
            // proxy && HTTP_(X_) FORWARDED (_FOR) not defined && HTTP_VIA defined
            // other exotic variables may be defined
            return ($HTTP_VIA . '_' . $HTTP_X_COMING_FROM . '_' . $HTTP_COMING_FROM);
            elseif ($HTTP_X_COMING_FROM || $HTTP_COMING_FROM)
            // case 3: proxy && only exotic variables defined
            // the exotic variables are not enough, we add the REMOTE_ADDR of the proxy
            return ($REMOTE_ADDR . '_' . $HTTP_X_COMING_FROM . '_' . $HTTP_COMING_FROM);
            else
            // case 4: no proxy or tricky case: proxy+refresh
            $clientip = $REMOTE_ADDR;
            //
            if (resolve == false) return ($clientip);
            //
            // /(\d+)(\.\d+){3}/)
            $b = ereg("^([0-9]{1,3}\.){3,3}[0-9]{1,3}", $clientip, $array);
            if ($b && (count($array) >= 1)) return (@gethostbyaddr($array[0]));
            else return ($clientip);
        }
    };
    //	Class
    //-------------------------------------------------------------------------
    
}
//	namespace
//-----------------------------------------------------------------------------
?>
Return current item: Entier Studio