Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_php thread: DNS name resolution


Message #1 by Gabriele Bartolini <angusgb@t...> on Tue, 08 May 2001 07:43:21 +0200
Ciao Gabriele,

of course (naturalmente) not 25 but 15 Bytes. I misspelled.

You somehow get your IP-Adress.

I guess from an Input-Box of a form. I mean... it's the same where you get
it from, important is you have a string with an IP-address and a maximum
length of 15.
The Variable is named $IP

You have to use the explode()-function. This function splits the string in
an array named $IPArray

$IPArray=explode(".", $IP);

If $IP is equal 36.4.167.192
then $IPArray will be
$IPArray[0]=36
$IPArray[1]=4
$IPArray[2]=167
$IPArray[3]=192

In your Insert-SQL-Statement you simply write
Insert into [Database] ..., IP1, IP2, IP3, IP4, ... values(..., $IPArray[0],
$IPArray[1], $IPArray[2], $IPArray[3], ...)

I hope you understand.

Ciao and arivederci
Bernhard

----- Original Message -----
From: "Gabriele Bartolini" <angusgb@t...>
To: "professional php" <pro_php@p...>
Sent: Tuesday, May 08, 2001 9:36 PM
Subject: [pro_php] Re: DNS name resolution


> Ciao Bernhard, thanks a lot!
>
> >you're totally right. Storing an IP-adress as a string takes 25 bytes,
> >stroring it as numbers takes 4 bytes.
>
> Yep, I was right! ;-)
>
> >What is your problem? You have the IP-adress as a string I assume. You
> >simply split it with the "." (dot) as delimiter. You then have an array
from
> >0 to 3 containing each number that easily can be used in the
> >INSERT-SQL-statement.
>
> Can you please give me an example? Should I use powers? I mean, kinda:
>
> $ip_address[0]=36;
> $ip_address[1]=4;
> $ip_address[2]=167;
> $ip_address[3]=192
>
> then use the 2 powers and get the results with a loop:
>
> $ip_value = 0;
>
> for ($i=0; $i<4; ++$i)
>      $ip_value=$ip_value + $ip_address[$i] * pow(256, $i);
>
> Is this right?
>
> I know I probably made a mistake in calculation of the value, but I am
> without my books ... I should go over them! ;-)
>


  Return to Index