-
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.
-
-
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.
-
The Following User Says Thank You to JasonDFR For This Useful Post:
-
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.
-
The Following User Says Thank You to Twey For This Useful Post:
-
Oo alright thanks for the explanation.
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks