#5842: getClientIP() possiblly return false IP address
-------------------------------------+--------------------------------------
    Reporter:  sdozono               |         Owner:  nate    
        Type:  RFC                   |        Status:  assigned
    Priority:  High                  |     Milestone:  1.2.x.x 
   Component:  General               |       Version:  RC3     
    Severity:  Normal                |    Resolution:          
    Keywords:  HTTP_X_FORWARDED_FOR  |   Php_version:  n/a     
Cake_version:                        |  
-------------------------------------+--------------------------------------
Comment (by sdozono):

 Some ideas....

 1:
 {{{
         function getClientIP($proxy_check=false) {

                 if($proxy_check){
                         if (env('HTTP_CLIENT_IP') != null){
                                 $ipaddr = env('HTTP_CLIENT_IP');
                         } elseif (env('HTTP_X_FORWARDED_FOR') != null) {
                                 $ipaddr = preg_replace('/(?:,.*)/', '',
 env('HTTP_X_FORWARDED_FOR'));
                         } else {
                                 $ipaddr = env('REMOTE_ADDR');
                         }
                 } else {
                         $ipaddr = env('REMOTE_ADDR');
                 }

                 if (env('HTTP_CLIENTADDRESS') != null) {
                         $tmpipaddr = env('HTTP_CLIENTADDRESS');

                         if (!empty($tmpipaddr)) {
                                 $ipaddr = preg_replace('/(?:,.*)/', '',
 $tmpipaddr);
                         }
                 }
                 return trim($ipaddr);
         }
 }}}

 2:
 {{{
         function getClientIP($proxy_check=false, $proxy_ips=array()) {

                 if($proxy_check == true){

                         if (env('HTTP_CLIENT_IP') != null){
                                 $ipaddr = env('HTTP_CLIENT_IP');
                         } elseif (env('HTTP_X_FORWARDED_FOR') != null){
                                 $ipaddr = preg_replace('/(?:,.*)/', '',
 env('HTTP_X_FORWARDED_FOR'));
                         } else {
                                 $ipaddr = env('REMOTE_ADDR');
                         }

                         if(count($proxy_ips) > 0){
                                 if(!in_array(env('REMOTE_ADDR'),
 $proxy_ips)){
                                         $ipaddr = $ipaddr."???";
 //We're not certain that this ip address is correct.
                                         //$ipaddr = env('REMOTE_ADDR');
 //local proxy address
                                 }
                         }

                 } else {
                         $ipaddr = env('REMOTE_ADDR');
                 }

                 if (env('HTTP_CLIENTADDRESS') != null) {
                         $tmpipaddr = env('HTTP_CLIENTADDRESS');

                         if (!empty($tmpipaddr)) {
                                 $ipaddr = preg_replace('/(?:,.*)/', '',
 $tmpipaddr);
                         }
                 }
                 return trim($ipaddr);
         }
 }}}

-- 
Ticket URL: <https://trac.cakephp.org/ticket/5842#comment:5>
CakePHP : The Rapid Development Framework for PHP <https://trac.cakephp.org/>
Cake is a rapid development framework for PHP which uses commonly known design 
patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC. 
Our primary goal is to provide a structured framework that enables PHP users at 
all levels to rapidly develop robust web applications, without any loss to 
flexibility.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"tickets cakephp" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/tickets-cakephp?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to