SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2002
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    IP Address and socket_create()

    How do I determine my IP address within a PHP program?



    The program below gets error “undefined function: socket_create()”



    However, http://us2.php.net/socket_create says “socket_create (PHP 4 >= 4.1.0, PHP 5)” and phpversion() is 4.3.6



    Program Below:

    $me=my_ip() ; echo "<br>".$me ;



    function my_ip($dest='64.0.0.0', $port=80)

    {

    $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);

    socket_connect($socket, $dest, $port);

    socket_getsockname($socket, $addr, $port);

    socket_close($socket);

    return $addr;

    }

  2. #2
    SitePoint Addict evilone's Avatar
    Join Date
    Oct 2004
    Location
    Estonia
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can get your ip address like this $_SERVER['REMOTE_ADDR']

  3. #3
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your "own IP address" is always 127.0.0.1, there is nothing you should care about
    If you meant, "IP address of my apache", it is $_SERVER['SERVER_ADDR']


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
  •