|
Posted by David Haynes on 02/15/06 21:23
frizzle wrote:
> Hi there,
>
> I'm saving ip addresses of blocked visitors into a mySQL DB.
> The function with wich i retrieve the address is below this message.
>
> What i wonder is, if it's ok to remove the dots from the ip address,
> and only
> save the numbers into the database. I assume it will be quicker to
> compare.
> But i don't know if it could mess up ip addresses. E.g. confuse
> 12.34.56.78 with 123.45.6.78
>
> Frizzle.
>
>
>
> --- function ---
>
> function getIp()
> {
> if ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) )
> {
> return $_SERVER['HTTP_X_FORWARDED_FOR'];
> }
> else
> {
> return $_SERVER['REMOTE_ADDR'];
> };
> };
>
If you want it without periods, you need to make the fields line up:
$ip_address = '10.0.1.126';
$foo = explode('.', $ip_address);
$padded = sprintf("%03d%03d%03d%03d", $foo[0], $foo[1], $foo[2], $foo[3]);
printf("ip = %s, padded = %s\n", $ip_address, $padded);
However, if you are going to explode the ip address, why not just store
the octet elements individually?
Also, what about IPv6?
-david-
[Back to original message]
|