note 41677 deleted from function.getenv by danbrown

From: Date: Sun, 20 Jul 2008 00:21:06 +0000
Subject: note 41677 deleted from function.getenv by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-141837@lists.php.net to get a copy of this message
Note Submitter: mayday at tria dot lv ---- daniele_dll: Your function hase a bug! If You check this IPs: $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; $_SERVER['HTTP_X_FORWARDED_FOR'] = '127.0.0.2,127.0.0.3'; the function will return this: Array ( [0] => 127.0.0.1 [1] => 127.0.0.3 ) Yes, the first element from 'HTTP_X_FORWARDED_FOR' is lost. The only fixes you need to make is to move down one line. This is the correct way: <?php function get_ip_list() { $tmp = array(); if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && strpos($_SERVER['HTTP_X_FORWARDED_FOR'],',')) { $tmp += explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']); } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $tmp[] = $_SERVER['HTTP_X_FORWARDED_FOR']; } $tmp[] = $_SERVER['REMOTE_ADDR']; return $tmp; } ?>

« previous php.notes (#141837) next »