Link to home
Start Free TrialLog in
Avatar of pdheady
pdheady

asked on

$_SERVER['REMOTE_ADDR']; not working in PHP5

Here is the error I get from the code below.

PHP Notice:  Undefined index:  REMOTE_ADDR

This causing my entire script to fail.

Running PHP 5.1.6 (cli) (built: Apr  7 2009 08:00:04)

<?
 
$ip=$_SERVER['REMOTE_ADDR'];
 
echo $ip;
 
?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Beverley Portlock
Beverley Portlock
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pdheady
pdheady

ASKER

That is just a snippet of my code. I always use <?php...  sorry for confusion

Yes, REMOTE_ADDR is showing up in phpinfo(); test page and I see my IP address there.

I checked /etc/php.ini and register globals is off which should be fine.
Avatar of pdheady

ASKER

Ok I found problem and it's really my fault.

I'm running a web-service and connecting with client to web-service from the same server, so my IP detection was working just that the script was failing on output because of other syntax errrors. When debug on command line it was complaining about PHP Notice:  Undefined index:  REMOTE_ADDR

It is detecting the IP, but this still leads me to ask why is PHP still outputting that error on command line?

PHP Notice:  Undefined index:  REMOTE_ADDR
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pdheady

ASKER

Thx