Hi! I'm new to php and I have this problem that's been bugging me the whole day. I learned today that for some reason I cannot get the IP address of the visitors of my site because the $remote_addr function is not working. Is it possible that somebody hacked into my server and somehow disable the function for me? The script was actually working perfectly for a week that's why it beats me that all of a sudden it stopped getting the visitors' IP address and logs on blank on the IP field of my mysql database instead. I created a simple script and uploaded it on two different server just to check if it only happens in my server and found out it's working on other server indeed. Here's the one that's not working: http://www.cjnavato.com/test.php This one works: http://johnmanalo.freehostia.com/test.php The first one display the IP address and my name while the other one only displays my name. I only have the following code: php: <?php echo "$REMOTE_ADDR"; echo "jc"; ?> I've also tried $_SERVER['REMOTE_ADDR'] but it still won't work. I hope you guys can help me. I'm more of a designer than a programmer and this is giving me a headache. Sad Father Marcuss
I don't know what version of PHP this was introduced, but is it possible that you are running an old PHP version on your website? Try something like this... if (getenv(HTTP_X_FORWARDED_FOR)) { $guest_ip = getenv(HTTP_X_FORWARDED_FOR); } else { $guest_ip = getenv(REMOTE_ADDR); } Echo "Your ip is ".$guest_ip; Code (markup):