How to detect iPad/iPhone hardware with PHP

Below a very useful snippet of PHP code that detects whether the person viewing your website is on a iPad or iPhone. Thanks to this solution you can redirect visitors to a different version of your website or just to another page.

if(strstr($_SERVER[‘HTTP_USER_AGENT’],’iPhone’) || strstr($_SERVER[‘HTTP_USER_AGENT’],’iPad’))
{

}