PHP header() လုပ်ဆောင်ချက်
ဥပမာ
စာမျက်နှာ caching ကိုတားဆီးရန် HTTP ခေါင်းစီးသုံးခုကိုပို့ပါ-
<?php
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache");
header("Pragma: no-cache");
?>
<html>
<body>
...
...
မှတ်ချက်- အသုံးပြုသူများသည် ဘရောက်ဆာ၏ မူရင်း ကက်ရှ်ဆက်တင်များကို ပြောင်းလဲရန် သတ်မှတ်ထားသည့် ရွေးချယ်မှုများ ရှိပါသည်။ အထက်ဖော်ပြပါ ခေါင်းစီးများကို ပေးပို့ခြင်းဖြင့် သင်သည် အဆိုပါဆက်တင်များထဲမှ တစ်ခုခုကို အစားထိုးပြီး ဘရောက်ဆာအား ကက်ရှ်မဖြစ်စေရန် တွန်းအားပေးမည်ဖြစ်သည်။
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
header() function သည် အကြမ်း HTTP header ကို client တစ်ခုထံ ပို့ပေးသည်။
အမှန်တကယ် output မပို့မီ header() function ကို ခေါ်ရမည် ဖြစ်ကြောင်း သတိပြုမိရန် အရေးကြီးပါသည်။
အထားအသို
header(header, replace, http_response_code)
ကန့်သတ်တန်ဖိုးများ
Parameter | Description |
---|---|
header | Required. Specifies the header string to send |
replace | Optional. Indicates whether the header should replace a previous similar header or add a new header of the same type. Default is TRUE (will replace). FALSE allows multiple headers of the same type |
http_response_code | Optional. Forces the HTTP response code to the specified value |
နည်းပညာဆိုင်ရာအသေးစိတ်
ပြန်ပို့တန်ဖိုး- | ဘာမှမဖြစ် |
---|---|
PHP ဗားရှင်း- | 4.0+ |
PHP Changelog- | PHP 5.1.2- ယခု တစ်ကြိမ်တည်းတွင် ခေါင်းစီးတစ်ခုထက်ပို၍ ပို့ခြင်းကို တားဆီးသည်။ ၎င်းသည် ခေါင်းထိုးထိုးတိုက်ခိုက်မှုများကို အကာအကွယ်ပေးသည်။ |
နောက်ထပ် ဥပမာများ
ဥပမာ
ထုတ်ပေးထားသော PDF ဖိုင်ကို သိမ်းဆည်းရန် သုံးစွဲသူအား အမှာစကား ပြောကြားပါစေ (အကြောင်းအရာ-သဘောထား သဘောထား ခေါင်းစီးကို အကြံပြုထားသော ဖိုင်အမည်ကို ပေးဆောင်ရန် အသုံးပြုပြီး သိမ်းဆည်းသည့် ဒိုင်ယာလော့ဂ်ဘောက်စ်ကို ပြသရန် ဘရောက်ဆာအား အတင်းအကြပ်)
<?php
header("Content-type:application/pdf");
// It will be called downloaded.pdf
header("Content-Disposition:attachment;filename='downloaded.pdf'");
// The PDF source is in original.pdf
readfile("original.pdf");
?>
<html>
<body>
...
...
❮ PHP Network ရည်ညွှန်းချက်