Jump to content

Archived

This topic is now archived and is closed to further replies.

fathermarcuss

$remote_addr not working :(

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.  ???

Share this post


Link to post
Share on other sites
it has to be $_SERVER['REMOTE_ADDR']; because it is a predefined variable. Are you sure it isnt working with that?

Share this post


Link to post
Share on other sites
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.  :'(

Share this post


Link to post
Share on other sites
That's weird, check whats into $_SERVER array and post it here.

[code]
print_r($_SERVER);
[/code]

Share this post


Link to post
Share on other sites
[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] => fathermarcuss@gmail.com [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 )

Share this post


Link to post
Share on other sites
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]<?php
phpinfo();
?>[/code]

Share this post


Link to post
Share on other sites
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.  ;D



if (!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");
}

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
no thats OK

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

Share this post


Link to post
Share on other sites
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  ;D

Thanks to you too, ToonMariner.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.