Web Hosting Forum Login
Not a member yet? Sign up

Getting ip address with PHP

  • FORUMS
  • WEB DESIGN
  • WEB HOSTING OFFERS
  • ADVERTISING
  • WEB HOSTING
  • REQUEST A HOST
  • BEST WEB HOSTING
  • QUICK MENU
  • REGISTER HERE - Join us for FREE
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2017
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thumbs Up/Down
    Received: 2/0
    Given: 2/0

    Getting ip address with PHP

    Hello,

    I'm trying to get my ip with:
    PHP Code:
    $_SERVER['REMOTE_ADDR']; 
    The thing is that i'm getting a different address with php than from websites like myip.com
    I've read that there is no 100% reliable way to get an ip address, but what would be my best option using only php?
    Thanks.

  2. #2
    Join Date
    Dec 2017
    Posts
    1
    Thanks
    0
    Thanked 1 Time in 1 Post
    Thumbs Up/Down
    Received: 2/0
    Given: 0/0
    Hello,
    You can try this:

    PHP Code:
        if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
            
    $ip $_SERVER['HTTP_CLIENT_IP'];
        } 
        elseif (!empty(
    $_SERVER['HTTP_X_FORWARDED_FOR'])) {
            
    $ip $_SERVER['HTTP_X_FORWARDED_FOR'];
        } 
        else {
            
    $ip $_SERVER['REMOTE_ADDR'];
        }
        echo 
    'ip is: '.$ip

  3. The Following User Says Thank You to cheapservers For This Useful Post:
    VirtuBox (01-14-2018)

Newer Threads

  1. portuguesedude
    macklong
    Replies: 5 | Views: 85
    Last post by macklong, 01-13-2018, 07:18 PM
  2. radwebhosting
    radwebhosting
    Replies: 0 | Views: 60
    Last post by radwebhosting, 01-08-2018, 03:29 PM
  3. robert4u
    robert4u
    Replies: 0 | Views: 110
    Last post by robert4u, 01-08-2018, 04:27 PM
  4. mobin
    mobin
    Replies: 0 | Views: 50
    Last post by mobin, 01-09-2018, 02:10 PM
  5. BlimpHosting
    BlimpHosting
    Replies: 0 | Views: 127
    Last post by BlimpHosting, 01-09-2018, 11:58 PM

Older Threads

  1. DanielN
    DanielN
    Replies: 0 | Views: 143
    Last post by DanielN, 01-05-2018, 02:28 PM
  2. 24x7serverman
    24x7serverman
    Replies: 2 | Views: 233
    Last post by 24x7serverman, 01-05-2018, 12:23 PM
  3. David Beroff
    OliveJ
    Replies: 3 | Views: 219
    Last post by OliveJ, Yesterday, 12:24 PM
  4. Setari
    Chris Worner
    Replies: 1 | Views: 46
    Last post by Chris Worner, 01-05-2018, 02:47 PM
  5. macklong
    macklong
    Replies: 1 | Views: 114
    Last post by macklong, 01-06-2018, 01:20 PM

Latest Threads

  1. austenite
    austenite
    Replies: 0 | Views: 3
    Last post by austenite, Today, 10:56 PM
  2. robert4u
    robert4u
    Replies: 0 | Views: 24
    Last post by robert4u, Yesterday, 06:18 PM
  3. OliveJ
    Floxera-Jose
    Replies: 2 | Views: 57
    Last post by Floxera-Jose, Today, 09:25 PM
  4. lisadolor
    24x7serverman
    Replies: 2 | Views: 60
    Last post by 24x7serverman, Yesterday, 08:54 AM
  5. Jigz Alvarina Lim
    Jigz Alvarina Lim
    Replies: 0 | Views: 28
    Last post by Jigz Alvarina Lim, Yesterday, 02:08 AM

Similar Threads

  1. Harry P
    AlbaHost
    Replies: 4 | Views: 1061
    Last post by AlbaHost, 03-08-2017, 02:31 PM
  2. wpspeedster
    Get Hostname from IP address?
    By wpspeedster in forum VPS Hosting
    24x7CSM
    Replies: 4 | Views: 1445
    Last post by 24x7CSM, 01-29-2017, 01:56 AM
  3. Maxoq
    Collabora
    Replies: 2 | Views: 1389
    Last post by Collabora, 01-25-2017, 11:44 PM
  4. denvercardonations
    GswHosting
    Replies: 5 | Views: 724
    Last post by GswHosting, 01-09-2017, 04:00 PM
  5. Tshepo
    hostslim
    Replies: 2 | Views: 778
    Last post by hostslim, 11-19-2015, 11:02 AM

Posting Permissions

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

Web Hosting Forum

ForumWeb.Hosting is a web hosting forum where youโ€™ll find in-depth discussions and resources to help you find the best hosting providers for your websites or how to manage your hosting whether you are new or experienced. Youโ€™ll find it all here. With topics ranging from web hosting, internet marketing, search engine optimization, social networking, make money online, affiliate marketing as well as hands-on technical support for web design, programming and more. We are a growing community of like-minded people that is keen to help and support each other with ambitions and online endeavors. Learn and grow, make friends and contacts for life.

Community

The world's smartest hosting providers come here to discuss & share what's trending in the web hosting world!
Copyright ยฉ2017, ForumWeb.Hosting. All rights reserved. Web Hosting Forum for webmasters, web hosting providers, designers and web developers.

Welcome to Forum Web Hosting

The World's Number 1 Web Hosting Community, Reviews & Services

Log in!

Continue with Facebook
Continue With Email. By signing up you indicate that you have read and agree to the Terms of Service and Privacy Policy.

Sign in Manually

Need an account? Sign up now!