redirect question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
adeenutza
Forum Newbie
Posts: 2
Joined: Mon Jan 18, 2010 8:50 am

redirect question

Post by adeenutza »

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!
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: redirect question

Post by AbraCadaver »

Check $_SERVER['HTTP_USER_AGENT'] and then use header() to redirect.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
adeenutza
Forum Newbie
Posts: 2
Joined: Mon Jan 18, 2010 8:50 am

Re: redirect question

Post by adeenutza »

The code from the first website shouldn't contain PHP
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: redirect question

Post by AbraCadaver »

adeenutza wrote:The code from the first website shouldn't contain PHP
Without javascript or PHP, the only way that I know of would be an .htaccess file if using Apache. You can use the RewriteCond %{HTTP_USER_AGENT} along with a RewriteRule.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply