android - Request desktop site option on mobile devices -
many mobile devices android phone have 'request desktop site' option. i'm in process of building mobile websites , want make native feature work.
what expected on our end developers? there request example: leave_mobile=1 or device changing user-agent trick application thinking desktop?
i've done tests on android devices , read out user agents , seems changes. did make native option work capture initial user agent session , on each page request compare 1 being sent. if user agent not same, revalidate if mobile device , if true overwrite session user-agent new one. if new validation fails, wants find desktop version send new header redirect.
$desktopsite = 'www.example.com'; $useragent = $_server['http_user_agent']; if (!isset($_session['use_mobile'])){ $_session['use_mobile'] = 1; $_session['user_agent'] = $useragent; } else if ($_session['user_agent'] != $useragent){ // check if user-agent has changed if(!preg_match( /*preg match http://detectmobilebrowsers.com/ */){ $_session['use_mobile'] = 0; $_session['user_agent'] = $useragent; // overwrite old user-agent new one. header("location: $desktopsite"); // send visitor desktop website. } else { // visitor still seems mobile. $_session['use_mobile'] = 1; $_session['user_agent'] = $useragent; // overwrite old user-agent new one. } }
if enter mobile website on desktop first time, not send desktop site because create session first. way can check mobile site on desktop instead of being send back. if change user-agent, revalidated , redirected on fail.
works perfectly. hope may in future.