질문 Q #22249
user_agent 관해 질문합니다.
비빅 2020-03-19 14:11:25

한번 코드 테스트 해볼려고 코드를 작성해서 했는데 

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Testview extends CI_Controller {

function index(){

$this->load->library('user_agent');

if ($this->agent->is_browser())

{

        $agent = $this->agent->browser().' '.$this->agent->version();

echo '컴퓨터';

}

elseif ($this->agent->is_robot())

{

        $agent = $this->agent->robot();

}

elseif ($this->agent->is_mobile())

{

        $agent = $this->agent->mobile();

echo '핸드폰';

}

else

{

        $agent = 'Unidentified User Agent';

}

echo $agent;

echo $this->agent->platform(); // Platform info (Windows, Linux, Mac, etc.)

}

}

?>

 

여기서 핸드폰으로 사이트를 들어가봣는데

컴퓨터Chrome 80.0.3987.132Windows 10

 

 

컴퓨터Chrome 80.0.3987.132Windows 10

이런식으로 출력이 되더군요.

왜그런지 전혀 모르겠습니다. ㅠㅠ

딱 핸드폰만 잡아내서 실행시키고싶은데..

 

 

 

답변 2
#1 변종원(웅파) 2020-03-19 14:30:00
모바일로 인식 못한 것 같네요. if문 분리해서 테스트해보세요.
#2 한대승(불의회상) 2020-03-19 14:30:41

application/config/user_agents.php 파일에 정의된 패턴대로 판정합니다.

정의되어 있지 않으면 원하는 결과가 안나옵니다.