CI 묻고 답하기

제목 user_agent 관해 질문합니다.
카테고리 CI 2, 3
글쓴이 비빅 작성시각 2020/03/19 14:11:25
댓글 : 2 추천 : 0 스크랩 : 0 조회수 : 9690   RSS

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

<?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

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

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

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

 

 

 

 다음글 페이지 이동 질문입니다. (4)
 이전글 aws SMS 모든 유저에게 메시지 전송 (2)

댓글

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

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

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