Author |
|
rage
Joined: 25 Apr 2007 Posts: 5 Location: Sweden
|
Posted: Wed 25 Apr '07 8:54 Post subject: $_SERVER['REMOTE_ADDR'] is always 0.0.0.0 |
|
|
I'm trying to get the REMOTE_ADDR from users visiting my site but I only get 0.0.0.0 from my variables. I'm using this function to get the vars. I've checked where the script goes and it end up on this line $IP=$_SERVER["REMOTE_ADDR"]; Do you think it might apache causing these problems? I'm not behind any kind of firewall or router. I've searched google and php-forums without result. The server was installed by wamp5_1.7.0
Code: | function getRemoteInfo(){
$proxy="";
$IP="";
if(isSet($_SERVER)){
if(isSet($_SERVER["HTTP_X_FORWARDED_FOR"])){
$IP=$_SERVER["HTTP_X_FORWARDED_FOR"];
$proxy=$_SERVER["REMOTE_ADDR"];
}elseif(isSet($_SERVER["HTTP_CLIENT_IP"])){
$IP=$_SERVER["HTTP_CLIENT_IP"];
}else{
$IP=$_SERVER["REMOTE_ADDR"];
}
}else{
if(getenv('HTTP_X_FORWARDED_FOR')){
$IP=getenv('HTTP_X_FORWARDED_FOR');
$proxy=getenv('REMOTE_ADDR');
}elseif(getenv('HTTP_CLIENT_IP')){
$IP=getenv('HTTP_CLIENT_IP');
}else{
$IP=getenv('REMOTE_ADDR');
}
}
if(strstr($IP, ',')){
$ips = explode(',', $IP);
$IP = $ips[0];
}
$RemoteInfo[0]=$IP;
$RemoteInfo[1]=@GetHostByAddr($IP);
$RemoteInfo[2]=$proxy;
return $RemoteInfo;
} |
My httpd.conf did not have the HostnameLookups so I added it at this line Code: | DefaultType text/plain
<IfModule mime_module>
[snip]
</IfModule>
#
# The mod_mime_magic module allows the server to use various hints from the
# contents of the file itself to determine its type. The MIMEMagicFile
# directive tells the module where the hint definitions are located.
#
#MIMEMagicFile conf/magic
HostnameLookups Off |
A snipped print_r gives:
Code: | Array
(
[HTTP_ACCEPT] => */*
[HTTP_ACCEPT_LANGUAGE] => sv
[HTTP_ACCEPT_ENCODING] => gzip, deflate
[HTTP_USER_AGENT] => Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727)
[HTTP_CONNECTION] => Keep-Alive
[HTTP_COOKIE] => PHPSESSID=edb5256bc20dafef07832ae121dcf64f
[SERVER_SIGNATURE] =>
[SERVER_SOFTWARE] => Apache/2.2.4 (Win32) PHP/5.2.1
[SERVER_PORT] => 80
[REMOTE_ADDR] => 0.0.0.0
[REMOTE_PORT] => 0
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => GET
[QUERY_STRING] =>
[REQUEST_TIME] => 1177355128
[argv] => Array
(
)
[argc] => 0
)
1 |
|
|
Back to top |
|
rage
Joined: 25 Apr 2007 Posts: 5 Location: Sweden
|
Posted: Wed 25 Apr '07 10:27 Post subject: |
|
|
Shouldn't this thread be moved here after we determine it is a php-problem? As you can see I get values from the other enviromental variables.
Can you with absolute certainty say it's not Apaches fault? In that case, please post why so I may continue my search.
Thanks |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Wed 25 Apr '07 10:34 Post subject: |
|
|
Which Windows do you run? Which Service Pack?
Here your script works fine
Code: |
print_r(getRemoteInfo());
|
Code: |
Array
(
[0] => 127.0.0.1
[1] => localhost
[2] =>
)
|
|
|
Back to top |
|
rage
Joined: 25 Apr 2007 Posts: 5 Location: Sweden
|
Posted: Wed 25 Apr '07 10:36 Post subject: |
|
|
Win2kpro SP4
Code: |
Array
(
[0] => 0.0.0.0
[1] => violette
[2] =>
) |
All visitors is logged and they all has been logged with 0.0.0.0 |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Wed 25 Apr '07 10:42 Post subject: |
|
|
OK the problem is known under W2k!
Try [b]Win32DisableAcceptEx[/code] in your httpd.conf and restart apache. If you haven't already done yet. |
|
Back to top |
|
rage
Joined: 25 Apr 2007 Posts: 5 Location: Sweden
|
Posted: Wed 25 Apr '07 10:47 Post subject: |
|
|
where in httpd.conf shall I put it? anywhere?
I'll try it when I get home from work |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Wed 25 Apr '07 11:35 Post subject: |
|
|
You can put that anywhere |
|
Back to top |
|
rage
Joined: 25 Apr 2007 Posts: 5 Location: Sweden
|
Posted: Wed 25 Apr '07 13:30 Post subject: |
|
|
thanks alot, works lika a charm now
wierd that I did not find any threads when I searched this forum with for 0.0.0.0 $_SERVER : /
Sorry for the extra thread ^^ |
|
Back to top |
|