PHP Cookies

cookie သည် အသုံးပြုသည် သည့် အခြား အသုံးပြုသည် ဖြစ်သည်။

cookie မှာ ဘယ်လိုဖြစ်သလဲ?

cookie သည် အသုံးပြုသည် သည့် အခြား အသုံးပြုသည် ဖြစ်သည်။ cookie သည် အက်ဥပဒေပြု အချက်အလက် တွင် အသုံးပြုသည် ဖြစ်သည်။ အခြား အက်ဥပဒေပြု အချက်အလက် ကို အခြား အက်ဥပဒေပြု အချက်အလက် ကို ကိုယ်စားပြုသည် အခါတွင် အခြား အက်ဥပဒေပြု အချက်အလက် ကို ပေးသည်။ PHP အက်ဥပဒေပြု ကို အသုံးပြုပြီး cookie ကို ဖန်တီးပြီး မြင်တွေ့နိုင်ပါ

cookie ကို ဖန်တီးရန် ဘယ်လိုဖြစ်သလဲ?

setcookie() ပုံစံ ကို cookie ကို တည်ဆောက်ရန် အသုံးပြုသည်。

အကြောင်းအရာsetcookie() ပုံစံ ကို <html> အချက်အလက် အတွင်းသို့ တည်ဆောက်ရမည်

အက္ခရာ

setcookie(name, value, expire, path, domain);

အမှတ်အသား

အောက်ပါ အမှတ်အသားတွင်,ကျွန်တော်တို့ အကယ်၍ "user" အမည်ရှိ cookie ကို ဖန်တီးပြီး "Alex Porter" ကို ချွတ်ချင်း ပေးခဲ့ပြီး တစ်နာရီ ပြီးဆုံးသည့် cookie ကို အသုံးပြုပါ:

<?php 
setcookie("user", "Alex Porter", time()+3600);
?>
<html>
<body>
</body>
</html>

အကြောင်းအရာcookie ကို ပေးချင်း ပေးခါတွင်,cookie ကို အစီအစဉ်အသုံးပြုရန် အားပေးသည် (URL အားသတ်မှတ်ကြောင်း အကယ်၍ အသုံးပြုရန် setrawcookie() ကို အစားထိုးပါ)。

Cookie ကို မြင်တွေ့ရန် ဘယ်လိုဖြစ်သလဲ?

PHP ၏ $_COOKIE ပုံစံ ကို အကယ်၍ cookie ကို မြင်တွေ့ရန် အသုံးပြုသည်。

အောက်ပါ အမှတ်အသားတွင်,ကျွန်တော်တို့ အကယ်၍ "user" အမည်ရှိ cookie ကို မြင်တွေ့ခဲ့ပြီး ပြင်းပြင်းတက်ကြားတွင် ပြသခဲ့သည်:

<?php
// အကယ်၍ cookie ကို နှုတ်ချရန်
echo $_COOKIE["user"];
// မျိုးမျိုးသော cookie ကို လေ့လာရန် တုန်း
print_r($_COOKIE);
?>

အောက်ပါ အမှတ်အသားတွင်,ကျွန်တော်တို့ အကယ်၍ isset() သဘောတူကြောင်း အတည်ပြုကြသည်:

<html>
<body>
<?php
if (isset($_COOKIE["user"]))
  အားလုံး လာပါတယ် " . $_COOKIE["user"] . "! <br />
else
  အားလုံး လာပါတယ်! <br />
?>
</body>
</html>

How to delete a cookie?

When deleting a cookie, you should change the expiration date to a past time point.

Example of deletion:

<?php 
// set the expiration date to one hour ago
setcookie("user", "", time()-3600);
?>

What if the browser does not support cookies?

If your application involves browsers that do not support cookies, you will have to take other methods to pass information from one page to another in the application. One way is to pass data from the form (we have already introduced forms and user input content earlier in this tutorial).

The following form submits the user input to "welcome.php" when the user clicks the submit button:

<html>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
</body>
</html>

Retrieve the value from "welcome.php" like this:

<html>
<body>
Welcome <?php echo $_POST["name"]; ?>.<br />
You are <?php echo $_POST["age"]; ?> years old.
</body>
</html>