Base64 encoding သည် binary data ကိုစာသားပုံစံဖြင့်ပြောင်းလဲစေသော encoding method တစ်ခုဖြစ်သည်။ ဤ encoding method သည် binary data များကိုအချို့သောစည်းမျဉ်းများအရစာသားပုံစံဖြင့်ပြောင်းလဲသည်, ထို့ကြောင့်သတင်းအချက်အလက်ဆုံးရှုံးခြင်းမရှိဘဲ binary data ကိုပုံမှန်အားဖြင့်ပြသနိုင်သည်။
Base64 encoding ကိုအဓိကအားဖြင့်အီးမေးလ်, HTTP protocol နှင့် binary data text format tward transmission သို့ပြောင်းလဲရန်လိုအပ်သည့်အချို့အခြေအနေများတွင်အသုံးပြုသည်။
PHP သည် base64_encode () function ကိုသုံးသော Base64_encode () function ကိုသုံးသည်။ ဤလုပ်ဆောင်ချက်၏ syntax သည်အောက်ပါအတိုင်းဖြစ်သည် -
string base64_encode(string $data)
$ ဒေတာသည် encoded ရန်လိုအပ်သည့် string ကိုဖြစ်ပါတယ်။
encoding အတွက် base64_encode () function ကိုအသုံးပြုသောနမူနာကုဒ်တစ်ခုရှိသည်။
$str = 'hello world';
$encode_str = base64_encode($str);
echo $encode_str; // aGVsbG8gd29ybGQ=
အထက်ဖော်ပြပါကုဒ်များတွင် string $ st string ကိုပထမဆုံးသတ်မှတ်ထားပြီး, ၎င်းသည် base64_encode () function ကို သုံး. encoded function_str.str.Str.str.Str_str.Str.str.Stain_str.Str.Str.Stain တွင်သိမ်းဆည်းထားသည်။
Encoding နှင့်သက်ဆိုင်သော PHP သည် baseb64 encoded strings များကို decode လုပ်ရန်ရိုးရှင်းသောနည်းလမ်းတစ်ခုကိုလည်းထောက်ပံ့ပေးသည်, ဆိုလိုသည်မှာ base64_decode () function ကိုသုံးသည်။ ဤလုပ်ဆောင်ချက်၏ syntax သည်အောက်ပါအတိုင်းဖြစ်သည် -
string base64_decode(string $data)
$ ဒေတာသည် decoded ခံရဖို့လိုအပ်တဲ့ base64-encoded string ကိုဖြစ်ပါတယ်။
Decoding အတွက် base64_decode () function ကိုအသုံးပြုသောနမူနာကုဒ်ဖြစ်သည်။
$encode_str = 'aGVsbG8gd29ybGQ=';
$decode_str = base64_decode($encode_str);
echo $decode_str; // hello world
အထက်ပါကုဒ်တွင် variable $ encode_Str_Str ကိုပထမ ဦး ဆုံးသတ်မှတ်ထားပြီး base64-encoded string ကိုသိမ်းဆည်းထားသည်။ ထို့နောက် Base64_Decode () function ကိုအသုံးပြုသည်။ Decoded Recoded VariDed Recode_str_str_str_str.str.Str.str.str.str.Str.struted တွင်သိမ်းဆည်းထားသည်။
Base64 encoding သည်လက်တွေ့ကျသောအပလီကေးရှင်းများတွင်အလွန်ပျံ့နှံ့နေသည်။ အောက်ဖော်ပြပါအချက်များမှာတိကျသော application တစ်ခုမှာ -
URL Parameters ၏ဖြတ်သန်းမှုသည် ASCII CLASTRESS SET ကိုအသုံးပြုရန်လိုအပ်သည်။ ထို့ကြောင့် Binary Data ကိုတိုက်ရိုက်မဖြတ်နိုင်ပါ။ ဤအချိန်တွင် binary data ကို base64 ကို အသုံးပြု. Set Set Set Set Set ကို ascii character ထဲသို့ encoded လုပ်နိုင်ပါတယ်။
ဥပမာအားဖြင့်, အောက်ပါဥပမာကုဒ်တွင် binary image data သည် based64_encode () function ကို အသုံးပြု. ပထမဆုံး encoded encoded encoded string ကို URL Parameter တစ်ခုအနေဖြင့်အခြားစာမျက်နှာတစ်ခုသို့ပို့သည်။
$img_data = file_get_contents('example.jpg');
$img_base64 = base64_encode($img_data);
$img_src = 'data:image/jpeg;base64,' . $img_base64;
အထက်ပါကုဒ်တွင်ဓာတ်ပုံ၏ binary data ကိုဖတ်ရန် file_get_contence () function ကိုပထမ ဦး စွာအသုံးပြုပါ။ ထို့နောက် Base64_encode () function ကိုသုံးပါ။
Base64 encoding သည် HTML စာမျက်နှာများသို့ထည့်သွင်းရန် Binary Data လိုအပ်သည့်အခြေအနေများတွင်အရေးကြီးသောအခန်းကဏ် play မှပါ 0 င်နိုင်သည်။
ဥပမာအားဖြင့်, အောက်ပါဥပမာကုဒ်တွင် PDF ဖိုင်သည် base64_encode () function ကို အသုံးပြု. ပထမဆုံး encoded encoded encoded string ကို dataurl အဖြစ် HTML စာမျက်နှာသို့ထည့်သွင်းထားသည်။
$pdf_data = file_get_contents('example.pdf');
$pdf_base64 = base64_encode($pdf_data);
$pdf_data_url = 'data:application/pdf;base64,' . $pdf_base64;
အထက်ပါကုဒ်တွင် PDF ဖိုင်၏ binary data ကိုဖတ်ရန် File_get_Contents () function ကိုပထမ ဦး စွာအသုံးပြုပါ။ PDF ဖိုင်၏ base64 string ကို encode လုပ်ပါ။
အမှန်တကယ် applications များအနေဖြင့်ကွန်ယက်ပေါ်တွင်ကူးစက်သောအခါ passwords နှင့်သော့များကဲ့သို့သော password နှင့် keys ကဲ့သို့သော privacy သတင်းအချက်အလက်များကိုခိုးယူနိုင်သည်။ ဤအချက်အလက်များ၏လုံခြုံရေးကိုကာကွယ်ရန်၎င်းကို base64 encoding ဖြင့်စာဝှက်ခြင်းနှင့်ထုတ်လွှင့်ရန်သာအသုံးပြုနိုင်သည်။
ဥပမာအားဖြင့်, အောက်ပါဥပမာကုဒ်တွင်စကားဝှက်အချက်အလက်များကို base64_encode () function ကို သုံး. ပထမ ဦး ဆုံး encoded သည်, ထို့နောက် encoded string ကိုဆာဗာသို့ပို့သည်။
$password = 'mypassword';
$encode_password = base64_encode($password);
// send $encode_password to server
ဆာဗာပေါ်ရှိ encrypted password အချက်အလက်ကိုလက်ခံရရှိပြီးနောက် Plass Text Password အချက်အလက်များရရှိရန်စကားဝှက်ကို decode လုပ်ရန် Base64_Decode () function ကိုသုံးနိုင်သည်။
$encode_password = 'bXlwYXNzd29yZA==';
$password = base64_decode($encode_password);
// use $password for authentication
Base64 encoding ဆိုသည်မှာ binary data များကိုစာသားပုံစံဖြင့် ပြောင်းလဲ. စာသားများကို protocols နှင့် programs များတွင်အသုံးပြုသည်။ PHP base64_encode () နှင့် base64_decode () functions များကို Base64 encoding နှင့် decoding အတွက်လုပ်ဆောင်ချက်များကိုထောက်ပံ့ပေးသည်။ ဤလုပ်ဆောင်ချက်နှစ်ခုသည် binary data နှင့်စာသားများအကြားအပြန်အလှန်ပြောင်းလဲခြင်းကိုနားလည်သဘောပေါက်နိုင်ပြီးလက်တွေ့ကျသော application များတွင်ကျယ်ပြန့်သောလျှောက်လွှာတန်ဖိုးရှိသည်။