Jump to content


Photo

$remote_addr not working :(


  • Please log in to reply
15 replies to this topic

#1 fathermarcuss

fathermarcuss
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 02 October 2006 - 06:43 AM

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

#2 ponsho

ponsho
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 02 October 2006 - 06:54 AM

maybe if you call the variable as $_SERVER['REMOTE_ADDR'] works

#3 fathermarcuss

fathermarcuss
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 02 October 2006 - 07:32 AM

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.  ???

#4 JasonLewis

JasonLewis
  • Members
  • PipPipPip
  • Advanced Member
  • 3,351 posts
  • LocationVictoria, Australia

Posted 02 October 2006 - 08:17 AM

it has to be $_SERVER['REMOTE_ADDR']; because it is a predefined variable. Are you sure it isnt working with that?
Good luck with your coding.
Jason / ProjectFear / Jaysonic

#5 fathermarcuss

fathermarcuss
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 02 October 2006 - 08:33 AM

Thanks, projectfear. 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.  :'(

#6 ponsho

ponsho
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 02 October 2006 - 08:53 AM

That's weird, check whats into $_SERVER array and post it here.

print_r($_SERVER);


#7 fathermarcuss

fathermarcuss
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 02 October 2006 - 08:58 AM

here you go:

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 )

#8 fathermarcuss

fathermarcuss
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 02 October 2006 - 09:01 AM

looks like it's working with that one, huh?

bummer! I really feel lost and stupid now  :D

#9 ponsho

ponsho
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 02 October 2006 - 09:04 AM

So its working now?

#10 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 02 October 2006 - 09:09 AM

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:
<?php
phpinfo();
?>


#11 fathermarcuss

fathermarcuss
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 02 October 2006 - 09:12 AM

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

#12 ponsho

ponsho
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 02 October 2006 - 09:16 AM

Try replacing $REMOTE_ADDR with $visitor_ipaddress

#13 fathermarcuss

fathermarcuss
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 02 October 2006 - 09:24 AM

thanks for clearing that up, wildteen88. 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?
register_globals Off Off

ponsho, i'll try your suggestion. thanks a lot.

#14 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 02 October 2006 - 09:30 AM

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!

#15 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 02 October 2006 - 09:31 AM

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
follow me on twitter @PHPsycho

#16 fathermarcuss

fathermarcuss
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 02 October 2006 - 09:32 AM

yes. it did work. thanks a lot guys.

thanks ponsho, ProjectFear and to you wildteen88

you guys will be rewarded in heaven ;D  ;D  ;D

Thanks to you too, ToonMariner.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users