Results 1 to 4 of 4

Thread: When to use which?

  1. #1
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default When to use which?

    I saw these 2 ways to get a users ip address which one is better to use, or is there a usage for each? Thanks.
    $ip=$_SERVER['REMOTE_ADDR']

    $ip=@$REMOTE_ADDR
    Last edited by bluewalrus; 01-19-2009 at 05:26 PM.

  2. #2
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    I'll take a stab. I tried a quick search for something like this and found a couple things, but no explanation. I may be totally wrong.

    I think that $REMOTE_ADDR is an old global variable that relies on register_globals being on. This is not good, and it is very likely that register_globals is not enabled on your server. Once PHP 6 is in use, register_globals won't even exist anymore.

    And the @ symbol surpresses errors. It is used in case there is a problem with the REMOTE_ADDR variable, I think...

    So ultimately the answer is to not use $ip=@$REMOTE_ADDR as it will probably not work.

    If someone knows more, let us know.
    Last edited by JasonDFR; 01-19-2009 at 08:03 AM.

  3. The Following User Says Thank You to JasonDFR For This Useful Post:

    bluewalrus (01-19-2009)

  4. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    No, you've pretty much hit it on the head.

    Anything that relies on a possibly-undefined global variable has been deprecated, since it's bad coding style and introduces security risks under certain circumstances. There are a bunch of autoglobal arrays you should use instead, such as $_SERVER, $_POST, $_GET, $_SESSION, and $_COOKIE.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. The Following User Says Thank You to Twey For This Useful Post:

    bluewalrus (01-19-2009)

  6. #4
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Oo alright thanks for the explanation.

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
  •