adeenutza Posted January 19, 2010 Share Posted January 19, 2010 I need to add some non-php code to the pages of a website for beeing able to redirect the user to a different website (a mobile version) in case the page was accesed from a mobile device. If user has javascript enabled, I can put a script that has as src a page from another website that checks with php if the device is mobile and, if it is, redirects the user with document.location.href to the mobile website. Is there any way I can do this redirect if the user doesn't have javascript? Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/188995-redirect-question/ Share on other sites More sharing options...
oni-kun Posted January 19, 2010 Share Posted January 19, 2010 You can get their browser user agent with $_SERVER['HTTP_USER_AGENT'], and that will be the only really non-js method of being able to read what they're on. If you install browscap.ini , You can use get_browser (instructions are on the page), and you'll be able to parse an array out of their user string, but it may only be for more common mobile OS's. If you're really wanting to find out their capability, use AJAX. If the form does not send any data, then JS can set the session to disable JS for the login session etc. EDIT: header will be your solution to redirect them, as it's an HTTP (non-js solution), add ob_start() to the beginning of your code if you wish to send the header after content is pushed to the client. Quote Link to comment https://forums.phpfreaks.com/topic/188995-redirect-question/#findComment-997865 Share on other sites More sharing options...
adeenutza Posted January 19, 2010 Author Share Posted January 19, 2010 The problem is that I am not able to use php on the first website, so I cannot add ob_start() at the beginning of the code. Quote Link to comment https://forums.phpfreaks.com/topic/188995-redirect-question/#findComment-997885 Share on other sites More sharing options...
marlonbtx Posted January 20, 2010 Share Posted January 20, 2010 I'm not sure but maybe you can use an Iframe and load the php code to check which device is .. but the proble i don't know if you can redirect the whole page Quote Link to comment https://forums.phpfreaks.com/topic/188995-redirect-question/#findComment-998802 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.