It is important to make your website accessible to all of your users. Although many people still access your website through their computer, a huge amount of people are also accessing your website from their phones and tablets. When you are programming your website it is important to keep these types of media in mind so that your site will work on these devices.
使所有用户都可以访问您的网站很重要。 尽管仍然有许多人通过计算机访问您的网站,但仍有大量人也通过手机和平板电脑访问您的网站。 在对网站进行编程时,请务必牢记这些媒体类型,以便您的网站可以在这些设备上运行。
PHP is all processed on the server, so by the time the code gets to the user, it is just HTML. So basically, the user requests a page of your website from your server, your server then runs all the PHP and sends the user the results of the PHP. The device never actually sees or has to do anything with the actual PHP code. This gives websites done in PHP an advantage over other languages that process on the user side, such as Flash.
PHP全部在服务器上处理,因此,在代码到达用户时,它只是HTML。 因此,基本上,用户从您的服务器请求您的网站页面,然后您的服务器运行所有PHP并将其结果发送给用户。 设备从不实际看到或必须对实际PHP代码执行任何操作。 这使用PHP完成的网站比其他在用户端处理的语言(例如Flash)更具优势。
It has become popular to redirect users to mobile versions of your website. This is something that you can do with the htaccess file but you can also do with PHP. One way to do this is by using strpos() to look for the name of certain devices. Here is an example:
将用户重定向到您网站的移动版本已变得很流行。 您可以使用htaccess文件执行此操作,但也可以使用PHP执行此操作。 一种方法是使用strpos()查找某些设备的名称。 这是一个例子:
<?php
$android = strpos($_SERVER['HTTP_USER_AGENT'],"Android");
$bberry = strpos($_SERVER['HTTP_USER_AGENT'],"BlackBerry");
$iphone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$ipod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod");
$webos = strpos($_SERVER['HTTP_USER_AGENT'],"webOS");
if ($android || $bberry || $iphone || $ipod || $webos== true)
{
header('Location: http://www.yoursite.com/mobile');
}
?>
If you chose to redirect your users to a mobile site, make sure you give the user an easy way to access the full site.
如果您选择将用户重定向到移动站点,请确保为用户提供了一种访问整个站点的简便方法。
Another thing to keep in mind is that if someone reaches your site from a search engine, they often aren't going through your home page so they don't want to be redirected there. Instead, redirect them to the mobile version of the article from the SERP (search engine results page.)
要记住的另一件事是,如果有人通过搜索引擎到达您的网站,他们通常不会进入您的主页,因此他们不想被重定向到该主页。 而是从SERP(搜索引擎结果页)将其重定向到文章的移动版本。
Something of interest may be this CSS switcher script written in PHP. This allows the user to put on a different CSS template via a drop-down menu. This would allow you to offer the same content in different mobile-friendly versions, perhaps one for phones and another for tablets. This way the user would have the option to change to one of these templates, but would also have the option to keep the full version of the site if they prefer.
有趣的是这个用PHP编写CSS切换器脚本。 这允许用户通过下拉菜单放置其他CSS模板。 这样一来,您就可以在不同的移动设备友好版本中提供相同的内容,也许一个用于手机,另一个用于平板电脑。 这样,用户可以选择更改为这些模板之一,但是如果愿意,还可以选择保留网站的完整版本。
One final consideration: Although PHP is good to use for websites that will be accessed by mobile users, people often combine PHP with other languages to make their sit do everything they want. Be careful when adding features that the new features won't make your site unusable by members of the mobile community. Happy programming!
最后要考虑的一个因素:尽管PHP非常适合移动用户访问的网站,但是人们经常将PHP与其他语言结合使用,以使自己的工作做自己想要的一切。 添加功能时要小心,新功能不会使您的网站无法被移动社区成员使用。 编程愉快!
翻译自: https://www.thoughtco.com/mobile-friendly-websites-2693900