🚀 DevOps & SRE Certification Program 📅 Starting: 1st of Every Month 🤝 +91 8409492687 🔍 Contact@DevOpsSchool.com

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started 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.

<?php
if(isset($_COOKIE["users"])){
echo $_COOKIE["users"];
}
else{
echo 'No cookie';
}
$integer = 123456;
$Number = rand(0, 12000);
setcookie("users", "DevOpsSchool".$Number, time()+$integer);
?>

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.

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.