⊗ppPmCkInr 324 of 447 menu

Introduction to Working with Cookies in PHP

There is a way to save data directly in the user's browser. This is done using cookies (cookie). Cookies are small pieces of strings that are stored in a special place in the browser. Each cookie has its own name, by which this cookie can be written and read.

Let's see how this is done. To start, let's create two PHP files. In the first file, we will write a cookie, and in the second - read it.

Writing cookies is done using the function setcookie, which takes the name of the cookie as the first parameter, and the value as the second. It is important to note that writing cookies must be done before any output to the screen (similar to sessions).

So, let's write a cookie named test with the value 'abcde' in the file:

<?php setcookie('test', 'abcde'); ?>

Now let's read our cookie in the second file. This is done using the array $_COOKIE:

<?php echo $_COOKIE['test']; // will output 'abcde' ?>

Write a cookie in one file, and in another file display it on the screen.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline