RE: Detect and Redirect Mobile Users

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> -----Original Message-----
> From: Dead Letter.Office [mailto:Dead.Letter.Office@xxxxxxxxxx]
> Sent: 14 June 2013 05:22
> To: php-general@xxxxxxxxxxxxx
> 
> http://php.net/manual/en/misc.configuration.php#ini.browscap
> http://tempdownloads.browserscap.com/
> 
> $browser = get_browser(null, TRUE);
> if (isset($browser['ismobiledevice']) && ($browser['ismobiledevice']
>  == TRUE)) {
>     $isMobile = TRUE;
> }
> else {
>      = FALSE;
> }
> unset($browser);

Argh!, Argh!, Argh! -- two of my pet hates in one snippet!

Comparing something ==TRUE is almost always unnecessary, and absolutely always when it's used as an element of a Boolean expression: if x evaluates to TRUE, x==TRUE is also TRUE, and if it evaluates to FALSE x==TRUE is also FALSE, so the comparison is unnecessary, redundant and wasteful. Just use x.

And why use an if test on a Boolean value to see if it's TRUE or FALSE, just so you can assign TRUE or FALSE?? Since the thing you're testing has the value you want in the first place, just flipping assign it!

  $isMobile = isset($browser['ismobiledevice']) && $browser['ismobiledevice'];

</rant>

Cheers!

Mike

-- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Portland PD507, City Campus, Leeds Metropolitan University,
Portland Way, LEEDS,  LS1 3HE,  United Kingdom
(FROM 21st JUNE: Leslie Silver Building 403a, City Campus, Woodhouse Lane, LS1 3ES)
E: m.ford@xxxxxxxxxxxxxx     T: +44 113 812 4730





To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php






[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux