Redirect to mobile php

Redirect to mobile website using PHP

Then, add this line to your .htaccess file: Question: I am looking for a way to redirect mobile browsers to a mobile specific version of my site. If you paste this in page that is HTML and not parsed by the server you’ll see this same code as output which will do nothing.

Redirect to mobile website using PHP

I have use this to generate this code:

But the only directions are to «copy and paste this code». Um.. copy and paste where? Do I need to create a new php file? Is this index.php ? What if I already have an index.html file?

EDIT: I understand that I put mobile_device_detect.php in the root of mydomain.com . My question is where to put the above PHP code.

Copy and paste this at the beginning of your PHP based pages that you want to detect the visitors for their device. If your server parses HTML files as PHP which I doubt then add this in your HTML files as well. If you’re just building the website then yes you need this in files which are parsed by the PHP engine for example: «.php». If you paste this in page that is HTML and not parsed by the server you’ll see this same code as output which will do nothing. In order to have it working you need it in PHP files. If your script is well written and well structured you may need to include it in only one place. It all depends how your website is structured.

Читайте также:  Foreach php one element

Why you shouldn’t be using this class? It have a special license which is not absolutely free. Instead you can use this simple class: https://github.com/serbanghita/Mobile-Detect

  1. Download Mobile_Detect.php
  2. Include the file at the top in your PHP page where you want the device to be checked:
// Include the mobile device detect class include 'Mobile_Detect.php'; // Init the class $detect = new Mobile_Detect(); // And here is the magic - checking if the user comes with a mobile device if ($detect->isMobile()) < // Detects any mobile device. // Redirecting header("Location: http://your_redirected_url.com"); exit; >
RewriteEngine On RewriteBase / RewriteRule ^your_page_name.html/?$ your_page_name.php [L] 

Save, close! Now you should be able to use your php page with .html extension. To access your page now just type: http://yourdomain.com/your_page_name.html Simple as that! Suggestion: If I was you I’d add the rewrite rules in the web server’s config file. It will be faster and more secure. But that’s another lesson. If you decide to use this method just search the Stack.

Copy and paste the code anywhere you want. Just make sure the function is defined on any page that needs it.

You should either buy the script mobile_device_detect.php from the site or use a free method called pay with a tweet option.. Go to the download page and you will see them there..

ok, in case this helps someone, here are the details of what’s working for me:

Create an index.php file with just this:

Drop the mobile_device_detect.php file in the root of your site.

Then, add this line to your .htaccess file:

DirectoryIndex index.php index.html 

Php — How to redirect mobile users to mobile version of, Redirect mobile devices to alternate version of my site (10 answers) Closed 9 years ago . I have a website www.domain.com and I have designed a new mobile version m.domain.com.

How to redirect to mobile site while still leaving the option open to view desktop version

I am looking for a way to redirect mobile browsers to a mobile specific version of my site. My issue is that I also need to provide a link in the mobile version that allows users to view the desktop site if they wish.

I could redirect based on browser, but then linking to the main site will only loop back to the mobile.

I can’t use a session variable, as I have a log in system that destroys the session data and so cause the user to return to the mobile site on logout.

I thought of using a redirect script as the index page to a separe desktop home page, but this would require restructuring my desktop site and play havoc with cms. I am unsure also what effect this would have on search engine ratings.

Can anyone thing of any other good way of handling this issue or will I have to bite the bullet and restructure my desktop site?

You should set a cookie (not a session cookie) when the user forces to see the desktop version sending a get paramter and then check its presence in the block where you detect the browser to redirect to the mobile version. Basically (pseudo-code):

# set the cookie if the user want to see the desktop version if GET[force-desktop-version] set_cookie(force-desktop-version = 1) end # check the cookie and the browser before redirecting if NOT get_cookie(force-desktop-version) and mobile_browser_used redirect_to the_mobile_version end 

Nope! there is a pretty simple way around this. You can check the last page the user visited in this way: document.referrer
Send the user to the mobile page if the referrer is any website other than the mobile page, if it is the mobile page, then you know that they clicked a ‘redirect to desktop version’ link.

Well on sign out page (where the session data is destroyed), just check if $_SESSION[‘mobile’] or some variable name is set to 1 or not. If it’s set to 1, then start session again and set only this value to 1 in new session before redirecting to homepage.

Redirect your website mobile users to your mobile site in, Are you looking for mobile website redirection script. Take a look at this post I want to explain how to detect mobile user agents like Android, Iphone and Blackberry. Many people are suggested to redirect with .htaccess file but I had implemented this with PHP. It is very easy just few lines of code. PHP Code: …

Best way to redirect single php page for mobile devices with PHP/Javascript

I have a PHP google map application that I want to make visible to users when they are using a desktop but redirect to another PHP page if the visitor is using a mobile device. I know there are numerous ways to do this from OS to browser type detection but was wondering if someone could provide some code they feel is the best way to handle this and it being the most consistent?

If you don’t want to use javascript, you can handle it via php. Take a look at this lib: http://code.google.com/p/php-mobile-detect/. And then you could do something like:

Disclaimer: I know this regex is not perfect, so don’t down vote just for that 🙂

Just wanted to share these few points.

  1. Some servers have $_SERVER[‘HTTP_USER_AGENT’] as not set, so make sure to check if empty first
  2. Readability is important to us, so we are using this instead of others complex regex. Just add other devices as you see fit.

Using the user-agent string

$useragent=$_SERVER['HTTP_USER_AGENT']; if(preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$useragent)||preg_match('/1207|6310|6590|3gso|4thp|504i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez(60|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n101|n202|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-(2|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-2|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|51|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i',substr($useragent,0,4))) header('Location: http://detectmobilebrowser.com/mobile'); 

Do you want javascript or php solution? Using JS you can just check if there is ‘Mobile’ in UA:

if (navigator.userAgent.indexOf('Mobile') > -1) location.href = 'your-mobile-page-url'; 

Источник

Как сделать мобильный редирект

Если вы используете WordPress или Joomla, вы можете воспользоваться специализированными плагинами для мобильного редиректа.
Google, рекомендует не использовать мобильный редирект вовсе (имеется ввиду не делать отдельный домен/поддомен для мобильного сайта), а сделать адаптивную верстку сайта.

    Редирект пользователей на мобильную версию сайта

RewriteEngine On
# Проверка mime типов, которые обычно поддерживаются мобильными устройствами
RewriteCond % «text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml» [NC]
RewriteCond % ^/$
RewriteRule ^ http://m.domain.com% [R,L]

    Редирект на мобильный сайт Используйте для определения мобильного устройства специальную библиотеку Mobile Detect, реализация есть практически для всех фреймворков и CMS (Репозиторий на GitHub)

// пример работы библиотеки Mobile Detect require_once ‘Mobile_Detect.php’;
$detect = new Mobile_Detect;
if ( $detect->isMobile() )
if ( $detect->isTablet() )
if ( $detect->isiOS() )
if ( $detect->isAndroidOS() )
?>

    Перенаправление на мобильную версию

Источник

Detect And Redirect To Mobile Site Using PHP

Mobile Site is one of the huge transformation we had seen in web due to the increasing number of mobile devices and of different sizes it becomes difficult to show appropriate version of website to the user.

So, in this tutorial we will show you how to detect and redirect to a mobile site using PHP.

There is a PHP class used for detecting mobile devices Mobile Detect we use this class to detect the mobile devices.

Detect And Redirect To Mobile Site Using PHP

To Detect And Redirect To Mobile Site It Takes Only Two Steps:-

  1. Make a PHP file and define markup for sample webpage
  2. Make a PHP file and define code to detect and redirect

Step 1. Make a PHP file and define markup for sample webpage

We make a PHP file and save it with a name detect_redirect.php

    

Detect And Redirect To Mobile Site Using PHP

In this step we create a sample page and add redirect.php page which is the main page used to detect and redirect to mobile site.

Step 2. Make a PHP file and define code to detect and redirect

We make a PHP file and save it with a name redirect.php

isMobile()) < header('Location: http://m.samplesite.com/'); exit; >// For All Tablet Devices if( $detect_device->isTablet()) < header('Location: http://m.samplesite.com/'); exit; >// For Specific Operating System if( $detect_device->isAndroidOS()) < echo ""; > if( $detect_device->isiOS()) < echo ""; > if( $detect_device->isWindowsPhoneOS()) < echo ""; >

In this step there are two ways to detect you can use global method which is isMobile and isTablet to detect mobile and tablet devices and redirect to mobile site.

You can also use specific styling for specific operating system like isAndroidOS is used to detect whether the user operating system is android or not if yes it use different css for android devices same as for ios and windows.

Thats all, this is how to detect and redirect to mobile site using PHP. You can customize this code further as per your requirement. And please feel free to give comments on this tutorial.

Источник

Оцените статью