Jump to content

redirect question


adeenutza

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.