cvs: phpweb /include ip-to-country.inc
| From: | Gabor Hojtsy | Date: | Sun, 04 May 2003 20:07:37 +0000 |
| Subject: | cvs: phpweb /include ip-to-country.inc | ||
| Groups: | php.mirrors | ||
| Request: | Send a blank email to php-mirrors+get-17308@lists.php.net to get a copy of this message | ||
goba Sun May 4 16:07:37 2003 EDT
Modified files:
/phpweb/include ip-to-country.inc
Log:
Use built in functions instead of user defined stuff.
Jome suggested this (from ip2nation). My test showed
that it does the same as our i2c_ip2number
Index: phpweb/include/ip-to-country.inc
diff -u phpweb/include/ip-to-country.inc:1.5 phpweb/include/ip-to-country.inc:1.6
--- phpweb/include/ip-to-country.inc:1.5 Sat May 3 16:06:01 2003
+++ phpweb/include/ip-to-country.inc Sun May 4 16:07:37 2003
@@ -1,6 +1,6 @@
<?php // -*- C++ -*-
-// $Id: ip-to-country.inc,v 1.5 2003/05/03 20:06:01 goba Exp $
+// $Id: ip-to-country.inc,v 1.6 2003/05/04 20:07:37 goba Exp $
/*
@@ -62,12 +62,12 @@
// User is behind a proxy
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
- $ipnum = i2c_ip2num($_SERVER['HTTP_X_FORWARDED_FOR']);
+ $ipnum = (float) sprintf("%u",
ip2long($_SERVER['HTTP_X_FORWARDED_FOR']));
}
// This is the real IP of the user
else {
- $ipnum = i2c_ip2num($_SERVER['REMOTE_ADDR']);
+ $ipnum = (float) sprintf("%u", ip2long($_SERVER['REMOTE_ADDR']));
}
// Find the index to start search from
@@ -83,18 +83,6 @@
return setcookie("COUNTRY", $country, time() + 60*60*24*7, '/',
'.php.net');
}
-// Convert a dotted IP address to a number.
-// (float) is important, as otherwise we would
-// get a signed value, which is not appropriate
-function i2c_ip2num($dotted)
-{
- $dotted = preg_split("/[.]+/", $dotted);
- return (float) ($dotted[0] * 16777216) +
- ($dotted[1] * 65536) +
- ($dotted[2] * 256) +
- ($dotted[3]);
-}
-
// Find nearest index entry for IP number
function i2c_search_in_index($ip)
{
@@ -185,4 +173,4 @@
{
global $COUNTRY;
return (!empty($COUNTRY) && $COUNTRY != "NA");
-}
\ No newline at end of file
+}