Hello. I am not sure if this is the correct place for this question. Please direct me if not. I am trying to set a webpage to redirect and display a different page if the first page is accessed from a mobile device (phone). Does anyone know how I can achieve this? I just need to know how to determine what it is viewed on. The redirect part I know already.
__________________
<DmncAtrny> I will write on a huge cement block "BY ACCEPTING THIS BRICK THROUGH YOUR WINDOW, YOU ACCEPT IT AS IS AND AGREE TO MY DISCLAIMER OF ALL WARRANTIES, EXPRESS OR IMPLIED, AS WELL AS DISCLAIMERS OF ALL LIABILITY, DIRECT, INDIRECT, CONSEQUENTIAL OR INCIDENTAL, THAT MAY ARISE FROM THE INSTALLATION OF THIS BRICK INTO YOUR BUILDING."
<DmncAtrny> And then hurl it through the window of a Sony officer
<DmncAtrny> and run like hell
The simplest way would be to test the viewport width and redirect if the width is less than whatever you decide is the widest that you want to redirect.
Although generally you shouldn't redirect, because you have to deal with two versions of your site; have you considered simply styling the page differently?
If you download this file and put it into your site and then put this into your index.php file:
It needs to end with .php or else the script won't work
PHP Code:
require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect();
if($detect->isMobile() or $detect->isTablet()){
header("Location: http://m.yoursite.com/");
}
The script is not hard or complicated, if you reed it you would probably understand it clearly.
This will redirect any mobiles or tablets to your mobile version of your site.
More info on how you can use the Mobile_Detect.php file can be found here.
Important notes: The file needs to be unzipped, and the content is going into your server.
The demo.php file is not necessary, only the Mobile_Detect.php file.
The Mobile_Detect.php file needs to be in the same directory as the file you put the script into.
Hello. I am not sure if this is the correct place for this question. Please direct me if not. I am trying to set a webpage to redirect and display a different page if the first page is accessed from a mobile device (phone). Does anyone know how I can achieve this? I just need to know how to determine what it is viewed on. The redirect part I know already.