0

I am getting this error: Call-time pass-by-reference has been deprecated; If you would like to pass it by reference, modify the declaration of ip_valid().

somewhere in these lines of code. Problem is I am not that strong in PHP to figure out what I need to modify to fix it.

Any advice would be apreciated.

function getIP () 
{
    $check = array(
            'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_FORWARDED_FOR',
            'HTTP_FORWARDED', 'HTTP_VIA', 'HTTP_X_COMING_FROM', 'HTTP_COMING_FROM',
            'HTTP_CLIENT_IP'
            );

    foreach ( $check as $c ) {
        if ( ip_valid ( &$_SERVER [ $c ] ) ) {
            return ip_first ( $_SERVER [ $c ] );
        }
    }

    return $_SERVER['REMOTE_ADDR'];

}

Thnaks in advance

Wayne

  • Here: `if ( ip_valid ( &$_SERVER [ $c ] ) ) {` – Mike B Apr 02 '13 at 12:49
  • I see answers stating _just remove the ampersand_ which of course will pass it by value. One could assume that there is a reason why it should have been passed by reference, failing to state that the declaration of `ip_valid` can also be changed to `ip_valid(&$ip_to_check);` – dbf Apr 02 '13 at 13:01

2 Answers2

1

Try without the ampersand:

ip_valid ( $_SERVER [ $c ] )

As with that you're forcing by-reference.

Although, noticeably you don't do this for the call to ip_first when passing in the same thing, so I would wonder what made you think it was right in the first place and why you did it differently in the second instance.

Grant Thomas
  • 44,454
  • 10
  • 85
  • 129
0

Just remove the & from ip_valid ( &$_SERVER [ $c ] ).

quad16
  • 184
  • 5
  • 20