Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/188995-redirect-question/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/188995-redirect-question/#findComment-997865
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.