SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: Ip

  1. #1
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ip

    How to get the ip address from users using php so that I can insert the ip in my database?

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Location
    Brisbane, Australia
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Using the Remote Address environmental variable:
    PHP Code:
    $ip $_SERVER['REMOTE_ADDR']; 
    Last edited by pixag employee; Jul 19, 2006 at 02:52.

  3. #3
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    getenv("HTTP_CLIENT_IP")

    getenv("REMOTE_ADDR")

    $_SERVER["REMOTE_ADDR"]; 

  4. #4
    SitePoint Guru toasti's Avatar
    Join Date
    Feb 2004
    Location
    Grahamstown
    Posts
    634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this one can get the persons real IP through a proxy:
    Code:
    $real_ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
    ..its failry accurate.

  5. #5
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks everyone!

  6. #6
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by toasti
    this one can get the persons real IP through a proxy:
    Code:
    $real_ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
    ..its failry accurate.
    although it _could_ be the users ip address behind a proxy, it could also be any value the user wants it to be. the server variables which are prefixed with HTTP_ are values which are part of the http request headers. this means the user could set these to any value they wish. you need to be careful with them.

  7. #7
    SitePoint Guru toasti's Avatar
    Join Date
    Feb 2004
    Location
    Grahamstown
    Posts
    634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    although it _could_ be the users ip address behind a proxy, it could also be any value the user wants it to be. the server variables which are prefixed with HTTP_ are values which are part of the http request headers. this means the user could set these to any value they wish. you need to be careful with them.
    good to know! I guess you could keep both just to be sure

  8. #8
    SitePoint Evangelist borna's Avatar
    Join Date
    Jun 2006
    Location
    Iran, Tehran
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up could run php codes via java

    Quote Originally Posted by clamcrusher
    although it _could_ be the users ip address behind a proxy, it could also be any value the user wants it to be. the server variables which are prefixed with HTTP_ are values which are part of the http request headers. this means the user could set these to any value they wish. you need to be careful with them.
    I know almost nothing from PHP . Please let me know where I should put such codes. In HTML or are they server side? Actually my platform is JSP/Servelt and I would like to know if it is possible to handle the job of taking IP via java codes. If no, please let me know if I should make a php file with code mentioned above and call that file in my menu. Am I right or no?
    My aim is to show him, just after logged in that with what ip is using my system. Next insert such ip in database. Hope I could get through the main point.
    Last edited by borna; Aug 5, 2006 at 00:18.


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
  •