$remote_addr not working :(
Posted 02 October 2006 - 06:43 AM
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.
Posted 02 October 2006 - 06:54 AM
Posted 02 October 2006 - 07:32 AM
Posted 02 October 2006 - 08:17 AM
Jason / ProjectFear / Jaysonic
Posted 02 October 2006 - 08:33 AM
Posted 02 October 2006 - 08:53 AM
Posted 02 October 2006 - 08:58 AM
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:188.8.131.52) Gecko/20060909 Firefox/184.108.40.206 [PATH] => /sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin [REMOTE_ADDR] => 220.127.116.11 [REMOTE_PORT] => 34216 [SCRIPT_FILENAME] => /home/httpd/vhosts/cjnavato.com/httpdocs/test2.php [SERVER_ADDR] => 18.104.22.168 [SERVER_ADMIN] => firstname.lastname@example.org [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/22.214.171.12423 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 )
Posted 02 October 2006 - 09:01 AM
bummer! I really feel lost and stupid now
Posted 02 October 2006 - 09:09 AM
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 126.96.36.199 for cjnavato.com. Does cjnavato.com have regsiter_globals enabled? You can chekc this by ruining the phpinfo function:
<?php phpinfo(); ?>
Posted 02 October 2006 - 09:12 AM
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.
$visitor_ipaddress = $_SERVER['REMOTE_ADDR'];
$visit_query = "SELECT * FROM visitors WHERE ip_address = '$REMOTE_ADDR'";
$result_query = mysql_query($visit_query);
$query = "INSERT INTO visitors (ip_address, visit_date, visit_time) " .
"VALUES ('$visitor_ipaddress', current_date, current_time)";
$new_visits = $visits + 1;
visit_date = current_date,
visit_time = current_time,
visits = (visits + 1)
ip_address = '$REMOTE_ADDR'");
Posted 02 October 2006 - 09:24 AM
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?
register_globals Off Off
ponsho, i'll try your suggestion. thanks a lot.
Posted 02 October 2006 - 09:30 AM
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!
Posted 02 October 2006 - 09:31 AM
ponsho 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
Posted 02 October 2006 - 09:32 AM
thanks ponsho, ProjectFear and to you wildteen88.
you guys will be rewarded in heaven
Thanks to you too, ToonMariner.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users