လက်ရှိတည်နေရာ: ပင်မစာမျက်နှာ> နောက်ဆုံးရဆောင်းပါးများစာရင်း> Get_Client_Version Tool အမျိုးအစားအတန်းကို Enhanced version ကိုဘယ်လို encapsult လုပ်နည်း

Get_Client_Version Tool အမျိုးအစားအတန်းကို Enhanced version ကိုဘယ်လို encapsult လုပ်နည်း

gitbox 1970-01-01

0 က်ဘ်ဆိုက်ဖွံ့ဖြိုးတိုးတက်မှုတွင် client version အချက်အလက်များကိုရယူခြင်း (ထိုကဲ့သို့သော browser, operating system, device system စသည်) သည်ဘုံလိုအပ်ချက်ဖြစ်သည်။ စာရင်းအင်းဆိုင်ရာခွဲခြမ်းစိတ်ဖြာခြင်းအတွက်အသုံးပြုသည်ဖြစ်စေအသုံးချနိုင်သည့်သဟဇာတဖြစ်သောသဟဇာတဖြစ်သောစီရင်ချက်သို့မဟုတ်ကိုယ်ပိုင်ပြသမှုကိုတိကျစွာခွဲခြားသတ်မှတ်ခြင်းသည်သုံးစွဲသူပတ် 0 န်းကျင်ကိုတိကျစွာခွဲခြားသိမြင်နိုင်သည်။

PHP ၏ကိုယ်ပိုင် $ _server ['http_user_agent'] သည် အခြေခံအကျဆုံးဖောက်သည်အချက်အလက်များကိုထောက်ပံ့ပေးသော်လည်းမလွယ်ကူပါ။ ဤအလုပ်ကိုပိုမိုထိရောက်စွာအဆင်ပြေစေရန်ပိုမိုကောင်းမွန်အောင်အဆင်ပြေစေရန်အတွက်ပိုမိုအားကောင်းသည့် Get_Client_Version function tool အတန်းအစားကိုကျွန်ုပ်တို့ပိုမိုထိရောက်သော browsers များ, operating systems များ, စက်ပစ္စည်းအမျိုးအစားများနှင့်အက်ပ်ဗားရှင်းများကိုပင်ခွဲခြားသတ်မှတ်ရန်ပိုမိုအားကောင်းလာနိုင်သည်။

1 ။ ထုပ်ပိုးမှုကိုအဘယ်ကြောင့်ပြုလုပ်ရန်လိုအပ်သနည်း။

မူရင်းအသုံးပြုသူ Agent String ကိုသုံးပြီးတိုက်ရိုက်အောက်ပါနာကျင်မှုအချက်များရှိသည်။

  • string format ကိုစည်းလုံးညီညွတ်မှုမရှိပါ။ ခွဲခြမ်းစိတ်ဖြာမှုများသည်ရှုပ်ထွေးနေသည်

  • ဘရောက်ဇာနှင့် operating system version များကိုမကြာခဏ update လုပ်ပြီးအသိအမှတ်ပြုနည်းလမ်းသည်မကြာခဏမမှန်ကန်ပါ

  • ပြောင်းလွယ်ပြင်လွယ်မှုနှင့်ပမာဏမရှိခြင်း,

ဤပြ problems နာများကိုကျော်လွှားရန်ကျွန်ုပ်တို့သည်စနစ်တကျ, modular နှင့်ကျယ်ပြန့်သောကိရိယာများကိုလိုအပ်သည်။

2 ။ ကိရိယာဒီဇိုင်းစိတ်ကူးများ

ကျွန်ုပ်တို့သည်အောက်ပါစွမ်းရည်များဖြင့် clientv persionalheler အတန်းကိုဖန်တီးရန်စီစဉ်ထားသည်။

  • browser အမျိုးအစားများနှင့်ဗားရှင်းများ (Chrome, Firefox, Safari စသည်) ကိုအလိုအလျောက်ခွဲခြားသတ်မှတ်ပါ။ )

  • operating system နှင့် version (Windows, MacOS, Linux, Android, iOS) ကိုအလိုအလျောက်ခွဲခြားသတ်မှတ်ပါ။

  • ၎င်းသည်မိုဘိုင်းစက်ရှိမရှိဆုံးဖြတ်ပါ

  • စိတ်ကြိုက် application header အသိအမှတ်ပြုခြင်း (ဥပမာ - Self-development apps များ၏ format များ)

  • စည်းလုံးညီညွတ်သောစနစ်တကျပြန်လာပုံစံကိုပေးပါ

3 ။ ကုဒ်အကောင်အထည်ဖော်မှု

အောက်ပါတို့သည်အနာဂတ်တွင်စီမံကိန်းလိုအပ်ချက်များနှင့်အညီနောက်ထပ်တိုးချဲ့နိုင်သည့်အခြေခံအကောင်အထည်ဖော်မှုဖြစ်သည်။

 <?php

class ClientVersionHelper
{
    protected $userAgent;

    public function __construct($userAgent = null)
    {
        $this->userAgent = $userAgent ?: ($_SERVER['HTTP_USER_AGENT'] ?? '');
    }

    public function getClientInfo()
    {
        return [
            'browser' => $this->getBrowser(),
            'os'      => $this->getOS(),
            'device'  => $this->isMobile() ? 'Mobile' : 'Desktop',
            'raw'     => $this->userAgent,
        ];
    }

    protected function getBrowser()
    {
        $ua = $this->userAgent;

        if (preg_match('/Chrome\/([0-9\.]+)/i', $ua, $matches)) {
            return 'Chrome ' . $matches[1];
        }

        if (preg_match('/Firefox\/([0-9\.]+)/i', $ua, $matches)) {
            return 'Firefox ' . $matches[1];
        }

        if (preg_match('/Safari\/([0-9\.]+)/i', $ua) && !preg_match('/Chrome/i', $ua)) {
            return 'Safari';
        }

        if (preg_match('/MSIE ([0-9\.]+)/i', $ua, $matches)) {
            return 'Internet Explorer ' . $matches[1];
        }

        return 'Unknown';
    }

    protected function getOS()
    {
        $ua = $this->userAgent;

        if (preg_match('/Windows NT ([0-9\.]+)/i', $ua, $matches)) {
            return 'Windows ' . $matches[1];
        }

        if (preg_match('/Mac OS X ([0-9_\.]+)/i', $ua, $matches)) {
            return 'macOS ' . str_replace('_', '.', $matches[1]);
        }

        if (preg_match('/Android ([0-9\.]+)/i', $ua, $matches)) {
            return 'Android ' . $matches[1];
        }

        if (preg_match('/iPhone OS ([0-9_]+)/i', $ua, $matches)) {
            return 'iOS ' . str_replace('_', '.', $matches[1]);
        }

        if (preg_match('/Linux/i', $ua)) {
            return 'Linux';
        }

        return 'Unknown';
    }

    protected function isMobile()
    {
        return preg_match('/Mobile|Android|iPhone|iPad/i', $this->userAgent);
    }
}

4 ။ ဥပမာများကိုသုံးပါ

စနစ်တကျ client version အချက်အလက်ကိုရိုးရိုးရှင်းရှင်းခေါ်ဆိုမှုဖြင့်ရရှိသည်။

 $clientHelper = new ClientVersionHelper();
$info = $clientHelper->getClientInfo();

echo '<pre>';
print_r($info);
echo '</pre>';

ပြန်လည်ရရှိခြင်း၏ဥပမာသည်အောက်ပါအတိုင်းဖြစ်သည် -

 Array
(
    [browser] => Chrome 120.0.0.0
    [os] => Windows 10.0
    [device] => Desktop
    [raw] => Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 ...
)

5 ။ ချဲ့ထွင်သော ဦး တည်ချက်အကြံပြုချက်များ

အောက်ပါ extensions များကိုလက်ရှိအခြေခံသို့ထည့်နိုင်သည်။

  • သင်၏ကိုယ်ပိုင်အက်ပလီကေးရှင်းအတွက် MyApp / 3.4.5 ကဲ့သို့သောစိတ်ကြိုက် UA Encentifiers များအတွက်ပံ့ပိုးမှုများကိုထည့်ပါ

  • device အသိအမှတ်ပြုမှုကိုပိုမိုထောက်ပံ့ရန် UA database ( https://gitbox.net/database ) ကိုပေါင်းစပ်ရန်

  • အပြောင်းအလဲနဲ့ထိရောက်မှုကိုတိုးတက်စေရန် cache ယန္တရားကိုပေးပါ

  • လွယ်ကူသောပြန်လည်အသုံးပြုခြင်းနှင့် update အတွက်ဤအတန်းကို composer အထုပ်ထဲသို့ oncapsulate

6 ။ နိဂုံးချုပ်

ထိရောက်သော get_cliesies_version tool အတန်းကို encapsulating encapsultien client မှအသိအမှတ်ပြု code ယုတ္တိဗေဒဆိုင်ရာယုတ္တိဗေဒကိုအလွန်ရိုးရှင်းရုံသာမကသင်၏လျှောက်လွှာကိုပိုမိုထိန်းသိမ်းနိုင်အောင်ပြုလုပ်နိုင်သည်။ ကိုယ်တိုင်အသုံးပြုသူအေးဂျင့်ကိုအချိန်တိုင်းခွဲနေသည့်အစား၎င်းကိုကိုင်တွယ်ရန်အစွမ်းထက်။ ယုံကြည်စိတ်ချရသောကိရိယာတစ်ခုသို့ထားခဲ့ပါ။

ကိရိယာနှင့် browser အမျိုးအစားများတိုးများလာခြင်းနှင့်အတူအထုပ်ကောင်းသောအထုပ်သည်သင်၏စီမံကိန်းကိုအသုံးပြုသူအသိအမှတ်ပြုမှု၏ရှေ့တန်းမှသိမ်းထားလိမ့်မည်။