On 7/19/07, tedd <[EMAIL PROTECTED]> wrote:
At 2:24 PM +0200 7/18/07, Olav Mørkrid wrote:
>consider the following statement:
>
>$language =
>isset($_SERVER["HTTP_ACCEPT_LANGUAGE"]) &&
>$_SERVER["HTTP_ACCEPT_LANGUAGE"] != "" ?
>$_SERVER["HTTP_ACCEPT_LANGUAGE"] : "*";
>
>when using strings in arrays that may be non-existing or empty, you
>have to repeat the reference *three* times, which gets excessive and
>unreadable.
>
>is there any way to only have to write
>$_SERVER["HTTP_ACCEPT_LANGUAGE"] only once?
>
>i know it's possible to supress "is not set" with @, but that just
>seems wrong in case there really is an error in the statement.
>
>i love php, but this is one of my pet peeves.
Olav:
Mine too.
But, Rasmus gave me this:
$action = isset($_GET['action']) ? $_GET['action'] : null;
Which could be translated to:
$language = isset
($_SERVER["HTTP_ACCEPT_LANGUAGE"]) ?
($_SERVER["HTTP_ACCEPT_LANGUAGE"]) : "*";
I think that might help.
Anyone see a problem with it?
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Since you're responding to someone else asking about such things where
there is the chance someone can just copy & paste... There really
should be a whitelist against your actions. This has the benefits of
making sure you know that your program is going to work as expected
whether or not a user is trying to be malicious or they copied the URL
incorrectly, etc.
This:
$action = isset($_GET['action']) ? $_GET['action'] : null;
Becomes:
$actions = array('one','two');
$action = (!empty($_GET['action']) AND in_array($_GET['action'], $actions))
? $_GET['action'] : null;
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php