Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

PHP intermediate essential guide- PHP setting cookies

In this blog, I am going to What is Php Cookies & How to use Cookies in PHP. PHP cookies are the same in all languages but the different types to write in all. So in this lesson, we’re going to talk about cookies and other ways to track users. PHP use for storing data from the page into the client machine (remote browser) or track & identifying return users. Cookies are part of the HTTP header setcookie() must be called before any output is sent to the browser.

Just looking at the cookie page here and this gives us some more information about how to use cookies. So the first thing that we want to do is set a cookie. And when we set a cookie so we’re going to give it a name. We’re going to give it a value and we’re going to give it time. And whatever this time is we can actually add to the time so we can take the current value and we’re going to add our value into time.

So this is a typical way to set a cookie. And again this is going to be when the cookie is going to expire. So with all cookies, you need to have this information. .cookie.So we’re going to give the cookie a name. So we’re just going to say the user and we’re going to give it a value and I set. So that’s all we have to do to set a cookie.

When run first time in the browser then show as mention below

after refresh the page then shown.

when you refresh multiple time then show different-different value every time.

Rajesh Kumar
Follow me
Latest posts by Rajesh Kumar (see all)