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
    radwebhosting
    Replies: 8 | Views: 149
    Last post by radwebhosting, 02-05-2018, 03:12 AM
  2. robert4u
    robert4u
    Replies: 0 | Views: 147
    Last post by robert4u, 01-08-2018, 04:27 PM
  3. mobin
    mobin
    Replies: 0 | Views: 75
    Last post by mobin, 01-09-2018, 02:10 PM
  4. BlimpHosting
    BlimpHosting
    Replies: 0 | Views: 201
    Last post by BlimpHosting, 01-09-2018, 11:58 PM
  5. Harry P
    Buy IP Address?
    By Harry P in forum Web Hosting
    Localnode
    Replies: 8 | Views: 714
    Last post by Localnode, 02-04-2018, 06:37 AM

Older Threads

  1. DanielN
    DanielN
    Replies: 0 | Views: 193
    Last post by DanielN, 01-05-2018, 02:28 PM
  2. 24x7serverman
    well-web
    Replies: 3 | Views: 522
    Last post by well-web, 01-30-2018, 10:00 PM
  3. David Beroff
    OliveJ
    Replies: 3 | Views: 500
    Last post by OliveJ, 01-22-2018, 12:24 PM
  4. Setari
    Chris Worner
    Replies: 1 | Views: 69
    Last post by Chris Worner, 01-05-2018, 02:47 PM
  5. manoaratefy
    manoaratefy
    Replies: 0 | Views: 100
    Last post by manoaratefy, 01-04-2018, 09:01 AM

Latest Threads

  1. Lampard
    Lampard
    Replies: 0 | Views: 4
    Last post by Lampard, Yesterday, 11:22 PM
  2. Lampard
    Lampard
    Replies: 0 | Views: 6
    Last post by Lampard, Yesterday, 11:21 PM
  3. Lampard
    Lampard
    Replies: 0 | Views: 7
    Last post by Lampard, Yesterday, 11:20 PM
  4. djsmiley2k
    VirtuBox
    Replies: 1 | Views: 45
    Last post by VirtuBox, Yesterday, 09:07 AM
  5. djsmiley2k
    djsmiley2k
    Replies: 0 | Views: 38
    Last post by djsmiley2k, 02-22-2018, 11:38 AM

Similar Threads

  1. Harry P
    AlbaHost
    Replies: 4 | Views: 1086
    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: 1479
    Last post by 24x7CSM, 01-29-2017, 01:56 AM
  3. Maxoq
    Collabora
    Replies: 2 | Views: 1409
    Last post by Collabora, 01-25-2017, 11:44 PM
  4. denvercardonations
    GswHosting
    Replies: 5 | Views: 757
    Last post by GswHosting, 01-09-2017, 04:00 PM
  5. Tshepo
    hostslim
    Replies: 2 | Views: 796
    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 ©2018, 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!