솔그루

그누보드5 코드 개선 with ChatGPT

그누보드 관리자 페이지의 방문자 분석 페이지를 보는데, os, 와 브라우저 정보가 제대로 표시되지 않습니다.

os 정보와 브라우저 파싱함수인 get_os(), get_brow() 함수가 오래전에 만들어져서 최신 user-agent 를 제대로 처리하지 못하네요.

 

방문자 정보를 제대로 표시하기 위해서 visit.lib.php 코드중 일부를 개선해보았습니다.

[code]

function get_brow($agent)
{
    $agent = strtolower($agent);

    if (preg_match("/msie ([1-9][0-9]\.[0-9]+)/", $agent, $m)) { $s = 'IE '.$m[1]; }
    else if (preg_match("/trident\/.*rv:([1-9][0-9]\.[0-9]+)/", $agent, $m)) { $s = 'IE '.$m[1]; } // For IE 11
    else if (preg_match("/edge\/([0-9\.]+)/", $agent, $m)) { $s = 'Edge '.$m[1]; }
    else if (preg_match("/edg\/([0-9\.]+)/", $agent, $m)) { $s = 'Edge(Chromium) '.$m[1]; } // For Chromium-based Edge
    else if (preg_match("/firefox\/([0-9\.]+)/", $agent, $m)) { $s = 'Firefox '.$m[1]; }
    else if (preg_match("/chrome\/([0-9\.]+)/", $agent, $m)) { $s = 'Chrome '.$m[1]; }
    else if (preg_match("/safari\/([0-9\.]+)/", $agent, $m)) { $s = 'Safari '.$m[1]; }
    else if (preg_match("/opera\/([0-9\.]+)/", $agent, $m)) { $s = 'Opera '.$m[1]; }
    else if (preg_match("/opr\/([0-9\.]+)/", $agent, $m)) { $s = 'Opera(Chromium) '.$m[1]; } // For Chromium-based Opera
    else if (preg_match("/bot|slurp|crawler|spider/", $agent)) { $s = 'Robot'; }
    else { $s = '기타'; }

    return $s;
}

function get_os($agent)
{
    $agent = strtolower($agent);

    if (preg_match("/windows nt 10\.0/", $agent)) { $s = "Windows 10"; }
    else if (preg_match("/windows nt ([0-9]\.[0-9])/", $agent, $matches)) { $s = "Windows NT ".$matches[1]; }
    else if (preg_match("/windows nt/", $agent)) { $s = "Windows NT"; }
    else if (preg_match("/windows ([0-9]+)/", $agent, $matches)) { $s = "Windows ".$matches[1]; }
    else if (preg_match("/windows/", $agent)) { $s = "Windows"; }
    else if (preg_match("/android ([0-9\.]+)/", $agent, $matches)) { $s = "Android ".$matches[1]; }
    else if (preg_match("/android/", $agent)) { $s = "Android"; }
    else if (preg_match("/iphone os ([0-9_]+)/", $agent, $matches)) { $s = "iOS ".str_replace("_", ".", $matches[1]); }
    else if (preg_match("/iphone/", $agent)) { $s = "iOS"; }
    else if (preg_match("/ipad/", $agent)) { $s = "iPadOS"; }
    else if (preg_match("/mac os x ([0-9_]+)/", $agent, $matches)) { $s = "macOS ".str_replace("_", ".", $matches[1]); }
    else if (preg_match("/macintosh|mac os x/", $agent)) { $s = "macOS"; }
    else { $s = "기타"; }

    return $s;
}

 

[/code]

 

전체 프롬프트

[code]

당신은 PHP 웹개발자입니다.

웹에서 접속시 user-agent header를 통해서  접속자의 여러 정보를 업을수 있습니다.

다음 함수는 user_agent 정보를 $agent 변수로 입력받아 , 접속한 기기의 디바이스와 os정보를 추출하는 함수입니다. 이 함수는 만들어진지 오래되어 최신 기기들의 정보를 정확하게 체크하지 못하고 있습니다. 최근 장비들과 브라우저정보도 체크할수 있도록 코드를 개선해주십시요.
get_os 함수는 os 종류를 구분하는게 기본 기능입니다.
window, ios, android, macos 를 제대로 구분하고, os 버전이 있는 경우에 구분할수 있게 파싱 코드를 개선하세요. 

{기존코드 get_os() 함수  복사 붙혀넣기}

[/code]

 

[code]

다음 함수는 user_agent 정보를 $agent 변수로 입력받아 , 접속한 기기의  브라우저 정보를 추출하는 함수입니다. 이 함수는 만들어진지 오래되어 최신 기기들의 정보를 정확하게 체크하지 못하고 있습니다. 최근 장비들과 브라우저정보도 체크할수 있도록 코드를 개선해주십시요.
{기존 get_brow() 함수 복사 붙혀넣기}

[/code]

 

|

댓글 4개

감사합니다. ^^
약간 이상하다고 느끼고 있었는데, 감사 합니다.
감사합니다. ^^
와우~ 이건 따로 피드백 해야겟네요~ 저렇게 깔끔하게 하시다닝

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기
🐛 버그신고