ChrisJonesCJ Posted February 8, 2009 Posted February 8, 2009 While doing my multi searches I noticed that two of my users have "unknown" ip. also double ip ###.###.###.##, ###.###.##.### I dont want to wrongly ban users but I am not sure what to do about this. Quote
mdshare Posted February 8, 2009 Posted February 8, 2009 Remote IP Detection use this instead, it will detect the remote IP, even if the player is behind a proxy function validip($ip) { if (!empty($ip) && ip2long($ip)!=-1) { $reserved_ips = array ( array('0.0.0.0','2.255.255.255'), array('10.0.0.0','10.255.255.255'), array('127.0.0.0','127.255.255.255'), array('169.254.0.0','169.254.255.255'), array('172.16.0.0','172.31.255.255'), array('192.0.2.0','192.0.2.255'), array('192.168.0.0','192.168.255.255'), array('255.255.255.0','255.255.255.255') ); foreach ($reserved_ips as $r) { $min = ip2long($r[0]); $max = ip2long($r[1]); if ((ip2long($ip) >= $min) && (ip2long($ip) <= $max)) return false; } return true; } else { return false; } } function getip() { if (validip($_SERVER["HTTP_CLIENT_IP"])) { return $_SERVER["HTTP_CLIENT_IP"]; } foreach (explode(",",$_SERVER["HTTP_X_FORWARDED_FOR"]) as $ip) { if (validip(trim($ip))) { return $ip; } } if (validip($_SERVER["HTTP_X_FORWARDED"])) { return $_SERVER["HTTP_X_FORWARDED"]; } elseif (validip($_SERVER["HTTP_FORWARDED_FOR"])) { return $_SERVER["HTTP_FORWARDED_FOR"]; } elseif (validip($_SERVER["HTTP_FORWARDED"])) { return $_SERVER["HTTP_FORWARDED"]; } elseif (validip($_SERVER["HTTP_X_FORWARDED"])) { return $_SERVER["HTTP_X_FORWARDED"]; } else { return $_SERVER["REMOTE_ADDR"]; } } ?> Quote
AlabamaHit Posted February 11, 2009 Posted February 11, 2009 Re: Strange Ip problem might sound crazy..... But how would i call the function? I tried to use it but ip comes blank so i know im diong it wrong, lol Quote
Guest Anonymous Posted February 11, 2009 Posted February 11, 2009 Re: Strange Ip problem echo the getip() function. echo getip(); Quote
AlabamaHit Posted February 11, 2009 Posted February 11, 2009 Re: Strange Ip problem lol Thanks....I didn't echo it, lol...thats why.. Once strange thing... It makes everyones IP mine............ i used echo getip(); any ideas.... Quote
Lithium Posted February 11, 2009 Posted February 11, 2009 Re: Strange Ip problem lol Thanks....I didn't echo it, lol...thats why.. Once strange thing... It makes everyones IP mine............ i used echo getip(); any ideas.... Where are you placing that bit? that is a pretty good replacement to $IP = .... $IP = getip(); Quote
AlabamaHit Posted February 11, 2009 Posted February 11, 2009 Re: Strange Ip problem i added it to viewuser.php. Quote
Dave Posted February 11, 2009 Posted February 11, 2009 Re: Strange Ip problem i added it to viewuser.php. No no no, Your supposed to have this for the updating part (lastip) (Think its in header) the viewuser part should stay the same Quote
AlabamaHit Posted February 11, 2009 Posted February 11, 2009 Re: Strange Ip problem ah i see. Will give a try and post back. Quote
Karlos Posted February 15, 2009 Posted February 15, 2009 Re: Strange Ip problem I have used MD's idea and i have error_reporting(E_ALL); on my WAMP server i get a bunch Undefined index does anyone know how to fix this and leave error_reporting(E_ALL); on? Notice: Undefined index: HTTP_CLIENT_IP in C:\wamp\www\Cursed-Islands (Re-Make)\global_func.php on line 417 Notice: Undefined index: HTTP_X_FORWARDED_FOR in C:\wamp\www\Cursed-Islands (Re-Make)\global_func.php on line 421 Notice: Undefined index: HTTP_X_FORWARDED in C:\wamp\www\Cursed-Islands (Re-Make)\global_func.php on line 428 Notice: Undefined index: HTTP_FORWARDED_FOR in C:\wamp\www\Cursed-Islands (Re-Make)\global_func.php on line 432 Notice: Undefined index: HTTP_FORWARDED in C:\wamp\www\Cursed-Islands (Re-Make)\global_func.php on line 436 Notice: Undefined index: HTTP_X_FORWARDED in C:\wamp\www\Cursed-Islands (Re-Make)\global_func.php on line 440 Quote
Karlos Posted February 15, 2009 Posted February 15, 2009 Re: Strange Ip problem Ahh good point. I've used it isset() before but i haven't fully got grasp on when and where to use it. EDIT: If you have error_reporting(E_ALL); on use this: function validip($IP) { if (!empty($IP) && ip2long($IP)!=-1) { $ReservedIps = array ( array('0.0.0.0','2.255.255.255'), array('10.0.0.0','10.255.255.255'), array('127.0.0.0','127.255.255.255'), array('169.254.0.0','169.254.255.255'), array('172.16.0.0','172.31.255.255'), array('192.0.2.0','192.0.2.255'), array('192.168.0.0','192.168.255.255'), array('255.255.255.0','255.255.255.255') ); foreach ($ReservedIps as $R) { $Min = ip2long($R[0]); $Max = ip2long($R[1]); if ((ip2long($IP) >= $Min) && (ip2long($IP) <= $Max)) return false; } return true; } else { return false; } } function getip() { if (validip(isset($_SERVER['HTTP_CLIENT_IP']))) { return $_SERVER['HTTP_CLIENT_IP']; } foreach (explode(",", isset($_SERVER['HTTP_X_FORWARDED_FOR'])) as $IP) { if (validip(trim($IP))) { return $IP; } } if (validip(isset($_SERVER['HTTP_X_FORWARDED']))) { return $_SERVER['HTTP_X_FORWARDED']; } else if (validip(isset($_SERVER['HTTP_FORWARDED_FOR']))) { return $_SERVER['HTTP_FORWARDED_FOR']; } else if (validip(isset($_SERVER['HTTP_FORWARDED']))) { return $_SERVER['HTTP_FORWARDED']; } else if (validip(isset($_SERVER['HTTP_X_FORWARDED']))) { return $_SERVER['HTTP_X_FORWARDED']; } else { return $_SERVER['REMOTE_ADDR']; } } Quote
Guest Anonymous Posted February 17, 2009 Posted February 17, 2009 Re: Strange Ip problem mm.. almost right... except a) it appears to handle an invalid list of reserved for internal use IPs b) it only handles IPv4 addresses Quote
Eternal Posted February 18, 2009 Posted February 18, 2009 Re: Strange Ip problem Umm Hi , I got told this will show the person behind the proxy? i tried this formular and it returned IP Hostname Last Hit 67.159.56.82 fsck.y-0-u.org Last Login 67.159.56.82 fsck.y-0-u.org That is no where near my real ip.... or ISP ip..... Is there some sort of trick to this that you know and i don't? Quote
Dave Posted February 20, 2009 Posted February 20, 2009 Re: Strange Ip problem Umm Hi , I got told this will show the person behind the proxy? i tried this formular and it returned IP Hostname Last Hit 67.159.56.82 fsck.y-0-u.org Last Login 67.159.56.82 fsck.y-0-u.org That is no where near my real ip.... or ISP ip..... Is there some sort of trick to this that you know and i don't? By anychance are you using a proxy? Quote
Karlos Posted March 10, 2009 Posted March 10, 2009 Re: Strange Ip problem The source of MD's posted code... http://www.teachmejoomla.net/code/php/r ... h-php.html Quote
mdshare Posted March 10, 2009 Posted March 10, 2009 Re: Strange Ip problem didn't come from there, is a snippet I have stored as 100s of other code snippets that might be usefull. Reason, simple websites die. happend more than once when going to a bookmarked site that it doesn't exist anymore. is the orig source http://algorytmy.pl/doc/php/function.getenv.php Quote
Karlos Posted March 10, 2009 Posted March 10, 2009 Re: Strange Ip problem I see, well the code was the same so you could of just agreed :lol: Quote
Karlos Posted March 13, 2009 Posted March 13, 2009 Re: Strange Ip problem I've been looking around and simple why not just use function IP($IP) { return long2ip(ip2long($IP)); } Example #3 IP validation ip2long() should not be used as the sole form of IP validation. Combine it with long2ip(): <?php // make sure IPs are valid. also converts a non-complete IP into // a proper dotted quad as explained below. $ip = long2ip(ip2long("127.0.0.1")); // "127.0.0.1" $ip = long2ip(ip2long("10.0.0")); // "10.0.0.0" $ip = long2ip(ip2long("10.0.256")); // "10.0.1.0" ?> Handles IPv4 Addresses Only. Quote
vampireduff Posted April 4, 2009 Posted April 4, 2009 Re: Strange Ip problem do I add the code to viewuser.php or header.php, and where abouts do I add it? Quote
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.