[phpMP-CVS] CVS: phpMP/core sessions.php,1.7,1.8
Status: Pre-Alpha
Brought to you by:
heimidal
From: Brian R. <hei...@us...> - 2003-09-22 10:38:05
|
Update of /cvsroot/phpmp/phpMP/core In directory sc8-pr-cvs1:/tmp/cvs-serv24754/core Modified Files: sessions.php Log Message: Moving IP stuff around. Index: sessions.php =================================================================== RCS file: /cvsroot/phpmp/phpMP/core/sessions.php,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -r1.7 -r1.8 *** sessions.php 22 Sep 2003 10:28:35 -0000 1.7 --- sessions.php 22 Sep 2003 10:38:01 -0000 1.8 *************** *** 30,34 **** var $_session_exists = false; var $_sess_key = false; - var $ip = false; function sess_start($create=true) --- 30,33 ---- *************** *** 64,71 **** $time = time(); $exp_time = $time + $Portal->cfg_get('session_length'); - $this->_sess_ip_encoded(); $session_exists = false; $user_id = false; if(!$this->_logged_in) { --- 63,88 ---- $time = time(); $exp_time = $time + $Portal->cfg_get('session_length'); $session_exists = false; $user_id = false; + + // IP fetching taken from phpBB2.2. + $ip = (!empty($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : getenv('REMOTE_ADDR'); + + if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) + { + $private_ip = array('#^0\.#', '#^127\.0\.0\.1#', '#^192\.168\.#', '#^172\.16\.#', '#^10\.#', '#^224\.#', '#^240\.#'); + foreach (explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']) as $x_ip) + { + if (preg_match('#([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)#', $x_ip, $ip_list)) + { + if (($ip = trim(preg_replace($private_ip, $ip, $ip_list[1]))) == trim($ip_list[1])) + { + break; + } + } + } + } + if(!$this->_logged_in) { *************** *** 244,266 **** } - } - - /** - * @return void - * @desc Fetches the user's IP in hex-encoded form. - * Taken from phpBB2. - */ - function _sess_ip_encoded() - { - $this->ip = $_SERVER['REMOTE_ADDR']; - - if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) - { - if (preg_match('#^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)#', $_SERVER['HTTP_X_FORWARDED_FOR'], $ip_list)) - { - $private_ip = array('#^0\.#', '#^127\.0\.0\.1#', '#^192\.168\.#', '#^172\.16\.#', '#^10\.#', '#^224\.#', '#^240\.#'); - $this->ip = preg_replace($private_ip, $this->ip, $ip_list[1]); - } - } } --- 261,264 ---- |