လက်ရှိတည်နေရာ: ပင်မစာမျက်နှာ> နောက်ဆုံးရဆောင်းပါးများစာရင်း> Custom Extension Get_Client_Version သည် 0 န်ဆောင်မှုခံယူသူများကိုပိုမိုထောက်ပံ့သည်

Custom Extension Get_Client_Version သည် 0 န်ဆောင်မှုခံယူသူများကိုပိုမိုထောက်ပံ့သည်

gitbox 2025-05-11

0 က်ဘ်အပလီကေးရှင်းများကိုတီထွင်သောအခါ client အသေးစိတ်အချက်အလက်များကိုနားလည်ခြင်းသည် granular အလုပ်လုပ်သောလိုက်လျောညီထွေဖြစ်အောင်ပြုလုပ်ခြင်း, PHP သည် 0 န် ဆောင်မှု ခံယူသူ၏ သုံးစွဲသူကိုယ်စားလှယ်အား လုပ်ငန်းများကိုလုပ်ဆောင်မှုများမှတဆင့်ခွဲနိုင်သည့်ပြောင်းလွယ်ပြင်လွယ် server-side ဘာသာစကားဖြစ်သည်။

1 ။ အခြေခံအတွေးအခေါ်များ

Get_Client_Version function ၏အဓိကရည်ရွယ်ချက်မှာ client ၏အမျိုးအစား (ထိုကဲ့သို့သော browser, operating system, device system, device system, device system, device system, device system, device system, device) နှင့်ဗားရှင်းအချက်အလက်များဖြစ်သည်။ ဤအရာကို _server ['http_user_agent'] ခွဲခြမ်းစိတ်ဖြာခြင်းဖြင့်ဤအရာကိုအကောင်အထည်ဖော်သွားမည်။

2 ။ function ကိုအကောင်အထည်ဖော်မှု

အောက်ဖော်ပြပါသည် Get_Client_Version_version function formation ၏အခြေခံဗားရှင်းဖြစ်ပြီးအသုံးပြုသူသတ်မှတ်ထားသော extension များတင်ခြင်းကိုထောက်ပံ့သည်။

 function get_client_version($user_agent = null, $custom_rules = []) {
    if (is_null($user_agent)) {
        $user_agent = $_SERVER['HTTP_USER_AGENT'] ?? '';
    }

    $clients = [
        'Chrome' => '/Chrome\/([0-9\.]+)/',
        'Firefox' => '/Firefox\/([0-9\.]+)/',
        'Safari' => '/Version\/([0-9\.]+).*Safari/',
        'Edge' => '/Edg\/([0-9\.]+)/',
        'Opera' => '/OPR\/([0-9\.]+)/',
        'Internet Explorer' => '/MSIE\s([0-9\.]+);/',
        'Windows' => '/Windows NT ([0-9\.]+)/',
        'macOS' => '/Mac OS X ([0-9_\.]+)/',
        'iOS' => '/iPhone OS ([0-9_\.]+)/',
        'Android' => '/Android ([0-9\.]+)/',
    ];

    // ထုံးစံစည်းမျဉ်းစည်းကမ်းများပေါင်းစည်း
    if (!empty($custom_rules) && is_array($custom_rules)) {
        $clients = array_merge($clients, $custom_rules);
    }

    $result = [];

    foreach ($clients as $name => $pattern) {
        if (preg_match($pattern, $user_agent, $matches)) {
            $result[$name] = str_replace('_', '.', $matches[1]);
        }
    }

    return $result;
}

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

 $client_info = get_client_version();

// output client ကိုသတင်းအချက်အလက်
echo '<pre>';
print_r($client_info);
echo '</pre>';

4 ။ Custom extension များကိုထောက်ပံ့ပါ

Customer account certical community community community commissions များပြုလုပ်နိုင်သည့် Customer accuss ည့်သည်များ,

 $custom_rules = [
    'MyAppClient' => '/MyApp\/([0-9\.]+)/'
];

$client_info = get_client_version(null, $custom_rules);

// output client ကိုသတင်းအချက်အလက်,ထုံးစံအကြောင်းအရာပါဝင်သည်
echo '<pre>';
print_r($client_info);
echo '</pre>';

V. ပုံမှန်လျှောက်လွှာအခြေအနေများ

  1. အသုံးပြုသူခွဲခြမ်းစိတ်ဖြာခြင်း - စာရင်းအင်းများစာရင်းအင်းများနှင့်အသုံးပြုသူများအသုံးပြုသောအသုံးပြုမှုဖြန့်ဖြူးခြင်း။

  2. အလုပ်လုပ်တဲ့သဟဇာတဖြစ်မှုကိုပြုပြင်ခြင်း

  3. လုံခြုံရေးမူဝါဒ - မထောက်ခံသောဖောက်သည်များကိုဖော်ထုတ်ပြီးလက်လှမ်းမီမှုကိုတားမြစ်သည်။

  4. API ကန့်သတ်ချက်များ - ဖောက်သည်အချို့ကို client information အပေါ် အခြေခံ. အချို့သော interfaces များကိုခေါ်ဆိုရန်ကန့်သတ်ထားသည်။

vi ။ ဖြန့်ကျက်အကြံပြုချက်များ

  • Get_Client_Version ကို စီမံကိန်း၏အများပြည်သူ 0 င်ခွင့်တွင်ခေါ်ယူရန်နှင့်ရလဒ်များကို $ _Session သို့မဟုတ် logging သို့ cache လုပ်ရန်အကြံပြုသည်။

  • မြင့်မားသောတစ်ပြိုင်နက်တည်းပတ်ဝန်းကျင်တွင်အဆင်သင့်ဖြစ်သည့်ခွဲခြမ်းစိတ်ဖြာခြင်းကိုရှောင်ရှားရန် Redis သို့မဟုတ် file cache ကိုပေါင်းစပ်ရန်အကြံပြုသည်။

7 ။ ရည်ညွှန်း link ကို

  • အသုံးပြုသူကိုယ်စားလှယ်အချက်အလက်များကို MDN ၏စာရွက်စာတမ်းများတွင် MDN ၏စာရွက်စာတမ်းများတွင်တွေ့နိုင်သည်။ https://devopoper.mozilla.org/

  • browser identifiers: https://www.useragentstring.com/