Identification with Cookies and Sessions in PHP

Cookies are simple flat text files (without format, without any decoration), created by the user's browser on their own computer, at the time the Web server requests it.

Identification with Cookies and Sessions in PHP | Learn PHP & MySQL | Cookies are simple flat text files (without format, without any decoration), created by the user's browser on their own computer, at the time the Web server requests it

Cookies: data that identify a browser

Cookies are simple flat text files (without format, without any decoration), created by the user's browser on their own computer, at the time the Web server requests it.

Cookies and php sessions

Within this text file, the user's browser will store the data that the server will send, and then - this is essential - the browser will automatically forward all the data to the server in each "request" the user makes to that same domain (that is, in each link that you press or in each form that leads to a page of that site that ordered you to create the cookie).

Browser sends cookie to server

That way, that server can identify that user throughout his navigation through the different pages of that same site, something that would serve both to show specific content created for that user, as for other tasks more invisible to the user but very useful for the owner of the site as, for example, keep statistics of the visits of each user.

Some possible uses: the server can store the user's name to greet him every time he enters a page of this site; memorize the products that you have chosen from a shopping cart until you complete the purchase operation; remember the language preferred by the user to navigate through that site; or the date of your last visit. And many other uses more.

The way a web server (typically Apache, the web server installed in most hostings) will order the user's browser (Firefox, Explorer, Opera, etc.). Create some of those text files called cookies, it will be totally under our control, since it would be our own PHP code that will order the web server that this, in turn, will ask the browser to create the cookie and, once created, another PHP code will be able to request that it be store data within that file, or read those stored there.

The way in which these text files are created on the user's hard drive should not worry us: that's the user's browser, after we execute the PHP instruction that, in a few moments, we will learn.

ATTENTION: this convenience of "the browser does everything" is a double-edged sword, because just as the browser simplifies our work, it can also prevent us from completely using cookies, if the user has configured his browser so that it does not let's create them. Therefore, when we use cookies, as far as possible, we should have an alternative B plan (for example, we would like to propose if it would not be better to use sessions) so as not to leave out those who have this option disabled in their browser.

🤖

ChatGPT Free
Ask questions on any topic

CITE ARTICLE


For homework, research, thesis, books, magazines, blogs or academic articles

APA Format Reference:

Delgado, Hugo. (2019).
Identification with Cookies and Sessions in PHP.
Retrieved Dec 13, 2024, from
https://disenowebakus.net/en/cookies-identification-sessions-php

Participates!

Share it with your friends in Social Networks!

Professor at the University of Guadalajara

Hugo Delgado Desarrollador y Diseñador Web en Puerto Vallarta

Professional in Web Development and SEO Positioning for more than 10 continuous years.
We have more than 200 certificates and recognitions in the Academic and Professional trajectory, including diploma certificates certified by Google.

CONTINUE LEARNING

IT ALSO DESERVES TO PAY TO VISIT:

Not finding what you need?

Use our internal search to discover more information
Related content:

Would you like to learn more about Web Design?

Meet all the courses and tutorials that we have for you completely free
Learn Web Design
 

Leave your Comment

SPONSOR

Your business can also appear here. More information

Your browser has blocked advertising.
Please 🙏 Allows you to view the ads to access, thank you.