{"id":135,"date":"2009-01-28T16:15:21","date_gmt":"2009-01-28T15:15:21","guid":{"rendered":"http:\/\/www.icantinternet.org\/?p=135"},"modified":"2016-11-30T07:07:47","modified_gmt":"2016-11-30T07:07:47","slug":"recognizing-the-iphone-for-webpages","status":"publish","type":"post","link":"https:\/\/beheydt.be\/en\/recognizing-the-iphone-for-webpages\/","title":{"rendered":"Recognizing the iPhone for webpages"},"content":{"rendered":"<p>As said in my <a title=\"Internet Earning in 2009\" href=\"\/?p=94\" target=\"_self\">2009 predictions<\/a>, the iPhone, and other mobile devices, will get a larger share in the tools your visitors use to visit your websites. So I suppose you will not be surprised when I tell you that it is very important to sure that your website is ready to receive your mobile customers.<\/p>\n<p><a class=\"thirstylink\" title=\"Goodlucky365 18pcs Phone Icon Magnet, Iphone App Magnets, Fridge Magnets,funny Magnets\" href=\"https:\/\/beheydt.be\/link\/others-amazon\/goodlucky365-18pcs-phone-icon-magnet-iphone-app-magnets-fridge-magnetsfunny-magnets\/\" target=\"_blank\" rel=\"nofollow\"><img loading=\"lazy\" decoding=\"async\" class=\"thirstylinkimg aligncenter\" title=\"Goodlucky365 18pcs Phone Icon Magnet, Iphone App Magnets, Fridge Magnets,funny Magnets\" src=\"https:\/\/beheydt.be\/wp-content\/uploads\/2016\/08\/61AJm5aUtFL.jpg\" alt=\"Goodlucky365 18pcs Phone Icon Magnet, Iphone App Magnets, Fridge Magnets,funny Magnets\" width=\"500\" height=\"500\" \/><\/a>The first step in this, is to let your webpage recognize if it is being visited by an iPhone. The best way to do this is by checking on the &#8220;user agent string&#8221;. For the not-knowers: this is a string of information of itself and its system that the browser sends to the webserver. In case of an iPhone, the user agent string looks something like this, depending on the language, the firmwareversion, and the country of origin:<\/p>\n<p style=\"padding-left: 30px;\">&#8211; Mozilla\/5.0 (iPhone; U; XXXXX like Mac OS X; en) AppleWebKit\/420+(KHTML, like Gecko) Version\/3.0 Mobile\/241 Safari\/419.3<\/p>\n<p style=\"padding-left: 30px;\">&#8211; Mozilla\/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit\/420+(KHTML, like Gecko) Version\/3.0 Mobile\/21A537a Safari\/419.3<\/p>\n<p>This user agent string can easily be used to detect if your webpage visitor is using an iPhone or a regular browser. The following short pieces of code return the user agent string, and show it in your webpage:<\/p>\n<p>JavaScript:<\/p>\n<p style=\"padding-left: 30px;\">&lt;script type=&#8221;text\/javascript&#8221;&gt;<\/p>\n<p style=\"padding-left: 30px;\">document.write(navigator.userAgent);<\/p>\n<p style=\"padding-left: 30px;\">&lt;\/script&gt;<\/p>\n<p>ASP:<\/p>\n<p style=\"padding-left: 30px;\">&lt;%=Request.ServerVariables(&#8220;HTTP_USER_AGENT&#8221;)%&gt;<\/p>\n<p>PHP:<\/p>\n<p style=\"padding-left: 30px;\">&lt;?php<\/p>\n<p style=\"padding-left: 30px;\">eco $_SERVER[&#8216;HTTP_USER_AGENT&#8217;];<\/p>\n<p style=\"padding-left: 30px;\">?&gt;<\/p>\n<p>As you may or may not know, once you can determine the type of browser being used, it is rather simple to forward Mobile Safari to the correct, iPhone optimized index page (perhaps called iphone_index.html or something):<\/p>\n<p>Javascript:<\/p>\n<p style=\"padding-left: 30px;\">&lt;html&gt;<\/p>\n<p style=\"padding-left: 30px;\">&lt;head&gt;<\/p>\n<p style=\"padding-left: 30px;\">&lt;script type=&#8221;text\/javascript&#8221;&gt;<\/p>\n<p style=\"padding-left: 30px;\">window.onload=function(){<\/p>\n<p style=\"padding-left: 30px;\">var agent=navigator.userAgent.toLowerCase();<\/p>\n<p style=\"padding-left: 30px;\">var is_iphone=agent.indexOf(&#8220;ipone&#8221;) !=-1;<\/p>\n<p style=\"padding-left: 30px;\">if(is_iphone){<\/p>\n<p style=\"padding-left: 60px;\">window.location=&#8221;iphone_index.html&#8221;<\/p>\n<p style=\"padding-left: 30px;\">}else{<\/p>\n<p style=\"padding-left: 60px;\">window.location=&#8221;other_index.html&#8221;;<\/p>\n<p style=\"padding-left: 30px;\">}<\/p>\n<p style=\"padding-left: 30px;\">}<\/p>\n<p style=\"padding-left: 30px;\">&lt;\/script&gt;<\/p>\n<p style=\"padding-left: 30px;\">&lt;body&gt;<\/p>\n<p style=\"padding-left: 30px;\">&lt;\/body&gt;<\/p>\n<p style=\"padding-left: 30px;\">&lt;\/html&gt;<\/p>\n<p>ASP:<\/p>\n<p style=\"padding-left: 30px;\">&lt;%<\/p>\n<p style=\"padding-left: 30px;\">useragent = Request.ServerVariables(&#8220;HTTP_USER_AGENT&#8221;)<\/p>\n<p style=\"padding-left: 30px;\">if instr(useragent, &#8220;iphone&#8221;) &gt; 0 then<\/p>\n<p style=\"padding-left: 30px;\">response.redirect(&#8220;iphone_index.html&#8221;)<\/p>\n<p style=\"padding-left: 30px;\">else<\/p>\n<p style=\"padding-left: 30px;\">response.redirect(&#8220;regular_index.html&#8221;)<\/p>\n<p style=\"padding-left: 30px;\">end if<\/p>\n<p style=\"padding-left: 30px;\">%&gt;<\/p>\n<p>PHP:<\/p>\n<p style=\"padding-left: 30px;\">&lt;?php<\/p>\n<p style=\"padding-left: 30px;\">$useragent= $_SERVER[&#8216;HTTP_USER_AGENT&#8217;];<\/p>\n<p style=\"padding-left: 30px;\">if(strpos($useragent, &#8216;iphone&#8217; &gt; 0)\u00a0{<\/p>\n<p style=\"padding-left: 60px;\">header(&#8220;Location: iphone_index.html&#8221;);<\/p>\n<p style=\"padding-left: 30px;\">}else{<\/p>\n<p style=\"padding-left: 60px;\">header(&#8220;Location: regular_index.html&#8221;);<\/p>\n<p style=\"padding-left: 30px;\">}<\/p>\n<p style=\"padding-left: 30px;\">?&gt;<\/p>\n<p>Of course, once you have this script in one of these languages to check if it is an iPhone, it can easily be extended to check for other types of browsers, and create optimized indexpages for those too.<\/p>\n<p>Happy coding! \ud83d\ude09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As said in my 2009 predictions, the iPhone, and other mobile devices, will get a larger share in the tools your visitors use to visit your websites. So I suppose you will not be surprised when I tell you that it is very important to sure that your website is ready to receive your mobile [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3525,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[942],"tags":[423,435,875],"class_list":["post-135","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-webdevelopment-icantinternet-en","tag-ipad","tag-iphone","tag-webdevelopment"],"jetpack_featured_media_url":"https:\/\/beheydt.be\/wp-content\/uploads\/2016\/08\/61AJm5aUtFL.jpg","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pbkKxJ-2b","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/beheydt.be\/en\/wp-json\/wp\/v2\/posts\/135","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/beheydt.be\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/beheydt.be\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/beheydt.be\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/beheydt.be\/en\/wp-json\/wp\/v2\/comments?post=135"}],"version-history":[{"count":0,"href":"https:\/\/beheydt.be\/en\/wp-json\/wp\/v2\/posts\/135\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/beheydt.be\/en\/wp-json\/wp\/v2\/media\/3525"}],"wp:attachment":[{"href":"https:\/\/beheydt.be\/en\/wp-json\/wp\/v2\/media?parent=135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/beheydt.be\/en\/wp-json\/wp\/v2\/categories?post=135"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/beheydt.be\/en\/wp-json\/wp\/v2\/tags?post=135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}