What are cookies and how to clear them in the browser, working with cookies in PHP and JS
Cookies or cookies (pronounced cookies, translated as cookies) are small files in the browser that are capable of storing text data. This is a useful mechanism, without which authorization is impossible on most sites today. Cookies are sent by the server, after which the browser installs them or they are installed via JavaScript (JS).
Sometimes you need to clear cookies - this can be done for all sites at once or only for one specific one. How to do this is shown below, the examples of clearing cookies refer to the browser "Google Chrome", in other browsers everything is the same.
How to clear all cookies
You may need to clear cookies in your browser in different cases, for example, to log out of accounts on different sites. To clear all cookies in the browser , follow these simple steps:
- go to "Settings";
- select the "Additional" item;
- select the "Clear history" item;
- in the window that appears, select "Cookies and other site data", as well as other items if necessary;
- click on the "Delete data" button.
How to clear cookies for one site
If you want to clear the data for only one specific site, you need to:
- open the desired site and click on the icon on the left next to the address bar;
- select "Cookie Settings";
- in the window that appears, select the required domain;
- click on the "Delete" button;
- click Finish and refresh the page if necessary.
How to work with cookies in PHP
How to work with cookies - how to set or get cookies? For this, the means of the programming language are used. For example, there are special functions for PHP, they are described on the official website in the section - php.net/manual/ru/features.cookies.php .
Main functions and features:
- setcookie - sends cookie;
- setrawcookie - send cookie without url encode value;
- $ _COOKIE is an array that automatically includes all cookies sent to the server by the visitor's browser. Accordingly, it is easy to get any cookie value from such an array anywhere.
How to work with JavaScript cookies
JavaScript also has accessibility features. The standard document.cookie property is used to read, write and delete cookies. It is a simple string in a special format, so for convenient work you will need additional functions that implement the necessary operations. Third party libraries such as jQuery Cookie are often used.
Sample, how to set, get or delete a cookie on jQuery Cookie :
// setting cookie
$ .cookie ('name', 'data', {path: '/', expires: 365});
// get cookie
$ .cookie ('name');
// delete cookie
$ .cookie ('name', null, {path: '/'});
// or
$ .removeCookie ('name', {path: '/'});
So, we found out that cookies are extremely useful for the operation of sites. Deleting or clearing cookies in your browser is very easy, just a few simple steps. Working with cookies in PHP and JavaScript is not difficult, there are special tools for this.
Latest articles
- 03.04.24IT / Уроки PHP Уроки простыми словами. Урок 3. Все операторы PHP с примерами, с выводом работы кода на экран.
- 02.04.24IT / Уроки PHP Уроки простыми словами. Урок 2. Типы данных в PHP с примерами.
- 02.04.24IT / Уроки PHP Уроки простыми словами. Урок 1. Коротко о языке веб-программирования PHP. Основы синтаксиса.
- 09.11.23IT / Database Errors when migrating from MySQL 5.6 to 5.7 and how to fix them - database dump import failed with an error or INSERT does not work. Disabling STRICT_TRANS_TABLES strict mode or using IGNORE
- 08.07.22IT / Misc Convert office files DOC, DOCX, DOCM, RTF to DOCX, DOCM, DOC, RTF, PDF, HTML, XML, TXT formats without loss and markup changes