12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?php
- namespace app\index\controller;
- use app\common\controller\Frontend;
- class Index extends Frontend
- {
- protected $noNeedLogin = '*';
- protected $noNeedRight = '*';
- protected $layout = '';
- public function index()
- {
- $isMobile = $this->isMobile();
- if ($isMobile) {
- //echo "手机访问";
- $this->redirect("/h5"); //关键代码重定向
- } else {
- //echo "PC访问";
- $this->redirect("/dist"); //关键代码重定向
- }
- // return $this->view->fetch();
- }
- function isMobile() {
- // 获取用户代理字符串
- $user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
- // 判断是否为手机
- $mobile_agents = array('iphone', 'ipod', 'ipad', 'android', 'mobile', 'blackberry', 'webos', 'incognito', 'webmate', 'bada', 'nokia', 'lg', 'ucweb', 'skyfire');
- $is_mobile = false;
- foreach ($mobile_agents as $device) {
- if (strstr($user_agent, $device)) {
- $is_mobile = true;
- break;
- }
- }
- return $is_mobile;
- }
- }
|