fathermarcuss Posted October 2, 2006 Share Posted October 2, 2006 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?I hope you guys can help me. I'm more of a designer than a programmer and this is giving me a headache. :(Father Marcuss Quote Link to comment https://forums.phpfreaks.com/topic/22717-remote_addr-not-working/ Share on other sites More sharing options...
ponsho Posted October 2, 2006 Share Posted October 2, 2006 maybe if you call the variable as $_SERVER['REMOTE_ADDR'] works Quote Link to comment https://forums.phpfreaks.com/topic/22717-remote_addr-not-working/#findComment-102155 Share on other sites More sharing options...
fathermarcuss Posted October 2, 2006 Author Share Posted October 2, 2006 Thanks for the reply, Ponsho. I've tried that already. Actually, I already have the script working for 2 weeks which is why I find it suspicious that it just stopped working all of a sudden. I was thinking maybe somebody hacked and changed may PHP configurations somewhere so it stops from being able to get the remote IP of the visitors. ??? Quote Link to comment https://forums.phpfreaks.com/topic/22717-remote_addr-not-working/#findComment-102157 Share on other sites More sharing options...
JasonLewis Posted October 2, 2006 Share Posted October 2, 2006 it has to be $_SERVER['REMOTE_ADDR']; because it is a predefined variable. Are you sure it isnt working with that? Quote Link to comment https://forums.phpfreaks.com/topic/22717-remote_addr-not-working/#findComment-102162 Share on other sites More sharing options...
fathermarcuss Posted October 2, 2006 Author Share Posted October 2, 2006 Thanks, [b]projectfear[/b]. Yes I'm sure it's not working. If you click on the link I gave above you will notice the the very same code I used is working on a different server. The script is working fine for two weeks that's why it beats that it stopped all of sudden and I didn't even changed anything on the script. Actually, any php scripts uploaded on that server can't get the remote IP of the visitors at all. :'( Quote Link to comment https://forums.phpfreaks.com/topic/22717-remote_addr-not-working/#findComment-102168 Share on other sites More sharing options...
ponsho Posted October 2, 2006 Share Posted October 2, 2006 That's weird, check whats into $_SERVER array and post it here.[code]print_r($_SERVER);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/22717-remote_addr-not-working/#findComment-102170 Share on other sites More sharing options...
fathermarcuss Posted October 2, 2006 Author Share Posted October 2, 2006 [b]here you go:[/b]Array ( [DOCUMENT_ROOT] => /home/httpd/vhosts/cjnavato.com/httpdocs [HTTP_ACCEPT] => text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 [HTTP_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.7 [HTTP_ACCEPT_ENCODING] => gzip,deflate [HTTP_ACCEPT_LANGUAGE] => en-us,en;q=0.5 [HTTP_CONNECTION] => keep-alive [HTTP_HOST] => www.cjnavato.com [HTTP_IF_MODIFIED_SINCE] => Fri, 03 Mar 2006 12:28:38 GMT [HTTP_IF_NONE_MATCH] => "173741-3bc-44083676" [HTTP_KEEP_ALIVE] => 300 [HTTP_USER_AGENT] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7 [PATH] => /sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin [REMOTE_ADDR] => 203.87.177.110 [REMOTE_PORT] => 34216 [SCRIPT_FILENAME] => /home/httpd/vhosts/cjnavato.com/httpdocs/test2.php [SERVER_ADDR] => 69.20.65.224 [SERVER_ADMIN] => [email protected] [SERVER_NAME] => www.cjnavato.com [SERVER_PORT] => 80 [SERVER_SIGNATURE] =>Apache/1.3.27 Server at www.cjnavato.com Port 80[SERVER_SOFTWARE] => Apache/1.3.27 (Unix) (Red-Hat/Linux) FrontPage/5.0.2.2623 mod_python/2.7.8 Python/1.5.2 mod_ssl/2.8.12 OpenSSL/0.9.6b DAV/1.0.3 PHP/4.3.11 mod_perl/1.26 mod_webapp/1.2.0-dev [GATEWAY_INTERFACE] => CGI/1.1 [SERVER_PROTOCOL] => HTTP/1.1 [REQUEST_METHOD] => GET [QUERY_STRING] => [REQUEST_URI] => /test2.php [SCRIPT_NAME] => /test2.php [PATH_TRANSLATED] => /home/httpd/vhosts/cjnavato.com/httpdocs/test2.php [PHP_SELF] => /test2.php [argv] => Array ( ) [argc] => 0 ) Quote Link to comment https://forums.phpfreaks.com/topic/22717-remote_addr-not-working/#findComment-102171 Share on other sites More sharing options...
fathermarcuss Posted October 2, 2006 Author Share Posted October 2, 2006 looks like it's working with that one, huh?bummer! I really feel lost and stupid now :D Quote Link to comment https://forums.phpfreaks.com/topic/22717-remote_addr-not-working/#findComment-102173 Share on other sites More sharing options...
ponsho Posted October 2, 2006 Share Posted October 2, 2006 So its working now? Quote Link to comment https://forums.phpfreaks.com/topic/22717-remote_addr-not-working/#findComment-102174 Share on other sites More sharing options...
wildteen88 Posted October 2, 2006 Share Posted October 2, 2006 My Ip address shows over at freehostia but it doesnt on the other site.Also no one can hack into your site and disable the REMOTE_ADDR variable. The server variables are defined via Apache or what ever webserver your webhosts uses.Also REMOTE_ADDR is set to 203.87.177.110 for cjnavato.com. Does cjnavato.com have regsiter_globals enabled? You can chekc this by ruining the phpinfo function:[code=php:0]<?phpphpinfo();?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/22717-remote_addr-not-working/#findComment-102176 Share on other sites More sharing options...
fathermarcuss Posted October 2, 2006 Author Share Posted October 2, 2006 the code you gave displayed my IP Adress but the actual script still can't get it.Here the actual code i'm I have. It logs on the IP addresses of the visitors. It counts the number of times a particular IP visits and it adds a new one if it's a new IP address. The problem is, it now logs on a blank IP for ALL the visitors and counts all of them as one since the they're all "blank" IPs now. Does that make sense?I really appreciate the help, guys. I'm a php virgin and my nose is bleeding now. ;Dif (!session_is_registered("counted")){ $visitor_ipaddress = $_SERVER['REMOTE_ADDR']; $visit_query = "SELECT * FROM visitors WHERE ip_address = '$REMOTE_ADDR'"; $result_query = mysql_query($visit_query); if (!$rows=mysql_fetch_array($result_query)) { $query = "INSERT INTO visitors (ip_address, visit_date, visit_time) " . "VALUES ('$visitor_ipaddress', current_date, current_time)"; mysql_query($query); } else { $new_visits = $visits + 1; mysql_query("UPDATE visitors SET visit_date = current_date, visit_time = current_time, visits = (visits + 1) WHERE ip_address = '$REMOTE_ADDR'"); } session_register("counted"); } Quote Link to comment https://forums.phpfreaks.com/topic/22717-remote_addr-not-working/#findComment-102177 Share on other sites More sharing options...
ponsho Posted October 2, 2006 Share Posted October 2, 2006 Try replacing $REMOTE_ADDR with $visitor_ipaddress Quote Link to comment https://forums.phpfreaks.com/topic/22717-remote_addr-not-working/#findComment-102181 Share on other sites More sharing options...
fathermarcuss Posted October 2, 2006 Author Share Posted October 2, 2006 thanks for clearing that up, [b]wildteen88[/b]. I'm really getting paranoid now coz it just stopped working all of a sudden.here's what I got so i guess this the reason why it stopped? do you have any idea why it was turned off all of a sudden?[b]register_globals Off Off[/b][b]ponsho,[/b] i'll try your suggestion. thanks a lot. Quote Link to comment https://forums.phpfreaks.com/topic/22717-remote_addr-not-working/#findComment-102187 Share on other sites More sharing options...
wildteen88 Posted October 2, 2006 Share Posted October 2, 2006 Most probably your host turned it off or they recently upgrade PHP. It i a good that regsiter globals is turned off. As it can cause security exploits in your code.However ponsho's suggestion should work.Always work with the superglobal arrays ( _GET, _POST, _SERVER, _COOKIE etc) regardles of the setting of register_globals if the host uses a PHP version greater than PHP4.2! Quote Link to comment https://forums.phpfreaks.com/topic/22717-remote_addr-not-working/#findComment-102192 Share on other sites More sharing options...
ToonMariner Posted October 2, 2006 Share Posted October 2, 2006 no thats OKponsho has it...In your script you declare $visitor_ipaddress = $_SERVER['REMOTE_ADDR']; but after that you refer to $REMOTE_ADDR which you have not defined previously - hence it will be empty Quote Link to comment https://forums.phpfreaks.com/topic/22717-remote_addr-not-working/#findComment-102193 Share on other sites More sharing options...
fathermarcuss Posted October 2, 2006 Author Share Posted October 2, 2006 yes. it did work. thanks a lot guys.thanks [b]ponsho[/b], [b]ProjectFear[/b] and to you [b]wildteen88[/b]. you guys will be rewarded in heaven ;D ;D ;DThanks to you too, ToonMariner. Quote Link to comment https://forums.phpfreaks.com/topic/22717-remote_addr-not-working/#findComment-102195 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.