SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: ip2long

  1. #1
    SitePoint Zealot
    Join Date
    Nov 2005
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ip2long

    I am facing the following problem:

    _ I have a file in my server checking the ip's from the visitors working perfectly but I am figuring an error in following code:

    PHP Code:
    $pagesource file_get_contents('http://myserver/ip.php');
    echo 
    $pagesource//correctly displayed ip: xxx.xxx.xxx.xxx
    $ip explode(":",str_replace(' '''$pagesource));
    echo 
    $ip[1]; //correctly displayed xxx.xxx.xxx.xxx

    echo ip2long($ip[1]); //ERROR! nothing displayed... 
    I have php 5.2.3 and if I use
    $ip[1]="127.0.0.1";
    echo ip2long($ip[1]);
    It works FINE

    What is my problem?

  2. #2
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try setting error_reporting to E_ALL and use var_dump instead of echo.

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2005
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    With error_reporting to E_ALL it does not report any error but it also does not display the echo ip2long($ip[1]);

    the most stupid thing it works with echo ip2long("127.0.0.1");

  4. #4
    Grumpy Minimalist
    Join Date
    Jul 2006
    Location
    Ontario, Canada
    Posts
    424
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:
    Code PHP:
    $pagesource = file_get_contents('http://myserver/ip.php');
     
    var_dump($pagesource); //correctly displayed ip: xxx.xxx.xxx.xxx
     
    $ip = explode(":",str_replace(' ', '', $pagesource));
     
    var_dump($ip[1]); //correctly displayed xxx.xxx.xxx.xxx
     
     
     
    var_dump(ip2long($ip[1])); //ERROR! nothing displayed...

    And in your php.ini file, make sure "display_errors" is set to "on".

  5. #5
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    This works for me
    PHP Code:
    <?php

    header
    ('Content-Type: text/plain');

    $pagesource file_get_contents('http://localhost/ip.php');
    $ip trim(array_pop(explode(':'$pagesource)));

    print 
    $ip ' = ' ip2long($ip);
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •