*In today’s world it is important to make your website accessible to all of your users. Although many people still access your website though their computer, a huge amount of people are also accessing your website from their phones and tablets. When you are programming your website it is important to keep these types of media in mind so that your site will work on these devices.
One good thing to know is that PHP pages work on all of these devices! The reason is that PHP is all processed on the server, so by the time the code gets to the user, it is just HTML. So basically, the user requests a page of your website from your server, your server then runs all the PHP and sends the user the results of the PHP. The device never actually sees or has to do anything with the actual PHP code. This gives websites done in PHP an advantage over other languages that process on the user side, such as Flash.
It has become popular to redirect users to mobile versions of your website. This is something that you can do with the htaccess file but you can also do with PHP. ( *about.com )
You need to check if the request came from a mobile phone device or desktop computer , use this function
- if ($this->RequestHandler->isMobile()) {
- /* condition for mobile device */
- }
- else {
- /* condition for PC */
- }
Core PHP Method
- function ismobile() {
- $is_mobile = ‘0’;
- if(preg_match(‘/(android|up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone)/i’, strtolower($_SERVER[‘HTTP_USER_AGENT’]))) {
- $is_mobile=1;
- }
- if((strpos(strtolower($_SERVER[‘HTTP_ACCEPT’]),‘application/vnd.wap.xhtml+xml’)>0) or ((isset($_SERVER[‘HTTP_X_WAP_PROFILE’]) or isset($_SERVER[‘HTTP_PROFILE’])))) {
- $is_mobile=1;
- }
- $mobile_ua = strtolower(substr($_SERVER[‘HTTP_USER_AGENT’],0,4));
- $mobile_agents = array(‘w3c ‘,‘acs-‘,‘alav’,‘alca’,‘amoi’,‘andr’,‘audi’,‘avan’,‘benq’,‘bird’,‘blac’,‘blaz’,‘brew’,‘cell’,‘cldc’,‘cmd-‘,‘dang’,‘doco’,‘eric’,‘hipt’,‘inno’,‘ipaq’,‘java’,‘jigs’,‘kddi’,‘keji’,‘leno’,‘lg-c’,‘lg-d’,‘lg-g’,‘lge-‘,‘maui’,‘maxo’,‘midp’,‘mits’,‘mmef’,‘mobi’,‘mot-‘,‘moto’,‘mwbp’,‘nec-‘,‘newt’,‘noki’,‘oper’,‘palm’,‘pana’,‘pant’,‘phil’,‘play’,‘port’,‘prox’,‘qwap’,‘sage’,‘sams’,‘sany’,‘sch-‘,‘sec-‘,‘send’,‘seri’,‘sgh-‘,‘shar’,‘sie-‘,‘siem’,‘smal’,‘smar’,‘sony’,‘sph-‘,‘symb’,‘t-mo’,‘teli’,‘tim-‘,‘tosh’,‘tsm-‘,‘upg1’,‘upsi’,‘vk-v’,‘voda’,‘wap-‘,‘wapa’,‘wapi’,‘wapp’,‘wapr’,‘webc’,‘winw’,‘winw’,‘xda’,‘xda-‘);
- if(in_array($mobile_ua,$mobile_agents)) {
- $is_mobile=1;
- }
- if (isset($_SERVER[‘ALL_HTTP’])) {
- if (strpos(strtolower($_SERVER[‘ALL_HTTP’]),‘OperaMini’)>0) {
- $is_mobile=1;
- }
- }
- if (strpos(strtolower($_SERVER[‘HTTP_USER_AGENT’]),‘windows’)>0) {
- $is_mobile=0;
- }
- return $is_mobile;
- }
Hello there I am so thrilled I found your weblog, I really found you by accident, while I
was searching on Digg for something else, Anyways I am here now and would just like to say thanks for a incredible
post and a all round thrilling blog (I also love
the theme/design), I don’t have time to read through
it all at the minute but I have bookmarked it and also included your RSS feeds, so when I have time
I will be back to read a lot more, Please do keep up the
awesome work.