SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Hybrid View

  1. #1
    SitePoint Addict goldensona's Avatar
    Join Date
    Jun 2011
    Posts
    226
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    how to get server ipaddress

    Hi

    i want to retrieve the server ip address, i have used this code for getting server ip address
    PHP Code:
    echo $_SERVER['SERVER_ADDR']; 
    this return local ip address instead of the displaying ip address in the url.

    why ? can any one tell the reason.. to solve this

    if the url contain the 12... means it return local 10...


    i want 12.. .

  2. #2
    Non-Member bronze trophy
    Join Date
    Nov 2009
    Location
    Keene, NH
    Posts
    3,760
    Mentioned
    23 Post(s)
    Tagged
    0 Thread(s)
    Huh? "in the url"?

    Could you explain better? I can't even make sense out of your post.

    SERVER_ADDR should be giving you the IP address of wherever that PHP code is being run -- aka the server it's being run from/on, not the client... The phrase "IP address in the URL" makes no sense whatsoever....well, unless you're calling the IP addy instead of by domain name...

  3. #3
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    You are getting a local IP address because you are connecting to the server from a local IP address.
    I assume you are wanting the IP address of your domain name, correct?
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  4. #4
    SitePoint Addict goldensona's Avatar
    Join Date
    Jun 2011
    Posts
    226
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth View Post
    You are getting a local IP address because you are connecting to the server from a local IP address.
    I assume you are wanting the IP address of your domain name, correct?
    yes i want the domain name ip address how to i get it?

  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)
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  6. #6
    SitePoint Addict goldensona's Avatar
    Join Date
    Jun 2011
    Posts
    226
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    thank you for your reply

    gethostbyname is work when we know domain name. if the url contiains 123.... how to i get ip address =123....

    if i use $_SERVER['REMOTE_ADDR'] it will return local ip of the system, i want ipaddress which is displaying in the url bar

  7. #7
    SitePoint Addict goldensona's Avatar
    Join Date
    Jun 2011
    Posts
    226
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    that is i need the public ip address of the server ?how do i get it can anyone help me

  8. #8
    Non-Member bronze trophy
    Join Date
    Nov 2009
    Location
    Keene, NH
    Posts
    3,760
    Mentioned
    23 Post(s)
    Tagged
    0 Thread(s)
    Wait, are you saying the public IP address isn't the one the server is at? that's screwy... behind a home router or something?

    If you are accepting requests by IP address, you could always pull it from REQUEST_URI instead.

    $domainPath=explode('/',trim(str_replace('http://','',$_SERVER['REQUEST_URI']),'/'));

    $domainPath[0] should then be either the IP address OR the domain name depending on the request type . If you NEED the IP address, test if it's a valid IP addy (another explode and four is_numeric?), if it isn't, then call gethostbyname.

  9. #9
    SitePoint Addict goldensona's Avatar
    Join Date
    Jun 2011
    Posts
    226
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your answer deathshadow60. i will try this approach.


    Quote Originally Posted by deathshadow60 View Post
    Wait, are you saying the public IP address isn't the one the server is at? that's screwy... behind a home router or something?

    If you are accepting requests by IP address, you could always pull it from REQUEST_URI instead.

    $domainPath=explode('/',trim(str_replace('http://','',$_SERVER['REQUEST_URI']),'/'));

    $domainPath[0] should then be either the IP address OR the domain name depending on the request type . If you NEED the IP address, test if it's a valid IP addy (another explode and four is_numeric?), if it isn't, then call gethostbyname.
    that is the ip address assign by some isp provider like if we go to What Is My IP Address? Lookup IP, Hide IP, Change IP, Trace IP and more... it will show the ip address provided by isp. my local ip 10.0...... if i run my script under my local ip it return 10.0..... i want to return ip address provided by isp.

  10. #10
    Non-Member bronze trophy
    Join Date
    Nov 2009
    Location
    Keene, NH
    Posts
    3,760
    Mentioned
    23 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by goldensona View Post
    that is the ip address assign by some isp provider like if we go to What Is My IP Address? Lookup IP, Hide IP, Change IP, Trace IP and more... it will show the ip address provided by isp. my local ip 10.0...... if i run my script under my local ip it return 10.0..... i want to return ip address provided by isp.
    That statement still makes no sense... I'm wondering if we have a terminology issue or something here. What do you mean "run it on my local IP"? Are you talking a local server like XAMPP or something? Something on your WAN that isn't exposed on the other side of your router?

    Either 1) you have the most bizzare hardware setup I've ever heard of, 2) you're failing to grasp how this stuff works -- or 3) I'm COMPLETELY missing your meaning entirely.


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
  •