Thread: integer URL

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    2
    Rep Power
    0
    I once found a PHP script that converted an IP address to an integer. Does anyone know where that script is?
  2. #2
  3. No Profile Picture
    ledjon
    Guest
    Devshed Newbie (0 - 499 posts)
    1. Why would you need that?

    2. IP addresses are already in integers, they're just divided by periods.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    24
    Rep Power
    0
    The following script converts IPs to their integer equiv. and vice versa. Use the example at the bottom for a demonstration. There's probably an easier way, but it works at least, heh.

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <?
    function longip($ip) {

    if (strstr($ip, "."))
    $islong = FALSE;
    else
    $islong = TRUE;

    if (!$islong) {
    $ip_sep = explode(".", $ip);

    $return = ( ( $ip_sep[0] * 0xFFFFFF + $ip_sep[0] )
    + ( $ip_sep[1] * 0xFFFF + $ip_sep[1] )
    + ( $ip_sep[2] * 0xFF + $ip_sep[2] )
    + ( $ip_sep[3] )
    );
    } else {
    $return = sprintf( "%d.%d.%d.%d",
    ( ( $ip >> 24 ) & 0xFF ),
    ( ( $ip >> 16 ) & 0xFF ),
    ( ( $ip >> 8 ) & 0xFF ),
    ( ( $ip ) & 0xFF )
    );
    }

    return($return);
    }

    $myip = "24.69.123.222";

    echo "My IP is: $myip<br><br>";
    echo "longip("$myip") = " . longip($myip) . "<br><br>";
    echo "longip(" . longip($myip) . ") = "" . longip(longip($myip)) . ""<br>";

    ?>
    [/code]

    Was this what you were after?

    ------------------

    - weeder

Similar Threads

  1. Changing video resolution from 1280 X 1024 to 1024 X 768
    By linh in forum Visual Basic Programming
    Replies: 4
    Last Post: January 21st, 2004, 02:46 PM
  2. Change ip url to domain
    By crypt1c_c0d3 in forum Apache Development
    Replies: 2
    Last Post: January 2nd, 2004, 10:55 AM
  3. w3c strict errors (10), css, and js questions
    By WorldBuilder in forum CSS Help
    Replies: 12
    Last Post: November 6th, 2003, 05:48 AM
  4. Help! How can I turn an integer into a string?
    By Vosper in forum C Programming
    Replies: 2
    Last Post: September 26th, 2003, 03:55 AM
  5. How to get the mac of network host??
    By cleverpig in forum Visual Basic Programming
    Replies: 1
    Last Post: September 23rd, 2003, 06:20 AM

IMN logo majestic logo threadwatch logo seochat tools logo