RE: $_SERVER['REMOTE_ADDR'] and sql injection

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Ashley Sheridan

> Out of interest, how does PHP calculate the IP number, as it was my
> understanding of IP numbers that they can't be negative.
> 
> For example, my IP address is 89.243.156.135
> The four parts as binary:
> 01011001
> 11110011
> 10011100
> 10000111
> 
> >From there, I thought that the binary values were concatenated as if
> they were a string, and then the decimal value worked out from that,
> giving, in my case, a value of 1509137543.
> 
> How is it possible that PHP can produce negative values from this
> method? Does it do something else entirely, or is this a case of the
> integer value overflowing into negative values? (which might explain
why
> the value correctly converts back)

When stored as a four byte integer, the high bit becomes the sign flag.
So if the first byte is 128 or higher, it would be converted into a
negative number.

This is a common issue when the size of numbers exceed the storage space
allotted. It's well understood in tightly typed languages, but often
missed in the more loosely typed languages like Perl and PHP.

Bob McConnell

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux