note 41677 added to function.getenv

From: Date: Mon, 19 Apr 2004 15:00:32 +0000
Subject: note 41677 added to function.getenv
Groups: php.notes 
Request: Send a blank email to php-notes+get-68331@lists.php.net to get a copy of this message
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; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.getenv.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+41677 Delete -- http://master.php.net/manage/user-notes.php?action=delete+41677&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+41677&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#68331) next »