Hello in this video, we will learn How to create and read Cookie in Javascript? Complete #phptutorials for #webapplications
What is a Cookie?
A cookie is a small file that is created on the user's computer to identify user and his preferences.
Each time the same computer requests a page with a browser, it will send the cookie too.
With PHP, we can create and retrieve cookie values created in JS.
Create a Cookie with JavaScript
JavaScript can create, read, and delete cookies with the document.cookie property.
With JavaScript, a cookie can be created like this:
document.cookie = "uname=Raj Kumar";
You can also add an expiry date (in UTC time). By default, the cookie is deleted when the browser is closed:
document.cookie = "uname=Raj Kumar; expires=Sun, 31 Dec 2023 12:00:00 UTC";
With a path parameter, you can tell the browser what path the cookie belongs to. By default, the cookie belongs to the current page.
Access Cookie using PHP
$_COOKIE[$cookie_name];
Access Cookie with JavaScript
With JavaScript, cookies can be read like this:
let x = document.cookie;
document.cookie will return all cookies in one string much like: cookie1=value; cookie2=value; cookie3=value;
Delete a Cookie with JavaScript
Deleting a cookie is very simple.
You don't have to specify a cookie value when you delete a cookie.
Just set the expires parameter to a past date:
document.cookie = "uname=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
For an Internship on Web Development contact +91-9939802016 or visit our website https://ssspatna.com
Смотрите видео How to create and read Cookie in Javascript? Complete онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Software Services and Solutions 06 Май 2023, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 10 раз и оно понравилось людям.