Gujarat Technological University
SAL INSTITUTE OF DIPLOMA STUDIES
DEPARTMENT OF INFORMATION TECHNOLOGY
Sem : 4th
ACADEMIC YEAR :- 2024-25
Web Development using PHP [4341604]
“PHP Cookies”
Hod [I.T.], GUIDED BY, Prepared by,
Ms. Dhara Dhruva Mr. Happy Mistry Joshi Shubham [234510316028]
CONTENT
1. Introduction to Cookies
2. Uses of Cookies
3. PHP and Cookies
4. Creating Cookies in PHP
5. Important Things About Cookies
6. Advantages of Cookies
7. References
Introduction To Cookies
• A cookie is often used to identify a
user. A cookie is a small file that the
server embeds on the user's computer.
• Each time the same computer
requests a page with a browser, it will
send the cookie too.
• With PHP, you can both create and
retrieve cookie values. PHP
transparently support HTTP Cookies.
• Cookies are the mechanism for
storing data in the remote browser
and thus tracking or identifying
return users.
Uses Of Cookies
• Remembering Login Details: Imagine you log into your favorite game website. A cookie can help
the website remember your username so you don't have to type it in every single time you come
back!
• Keeping Track of Your Shopping Cart: If you're buying something online and you add items to
your cart, a cookie helps the website remember what you've put there, even if you go to a different
page or close the website and come back later.
• Saving Your Preferences: Have you ever set a website to be in a certain language or have a
specific look? Cookies can store these choices so the website looks the way you like it each time
you visit.
• Personalizing Your Experience: Some websites use cookies to see what kind of things you're
interested in. Then, they can show you other things you might like, like recommending videos or
articles.
• Tracking Website Visits (in general): Website owners can use cookies to see how many people
visit their site and which pages are the most popular. This helps them make their website better for
everyone.
• Remembering if You've Seen Something: Sometimes, websites show you a pop-up or a special
message only once. A cookie can remember that you've already seen it, so it doesn't keep showing
up every time you visit.
Creating Cookies In PHP
• A cookie is created with
the setcookie() function.
• The value of the cookie is automatically
URLencoded when sending the cookie,
and automatically decoded when
received (to prevent URLencoding, use
setrawcookie() instead).
• To modify a cookie, just set (again) the
cookie using the setcookie() function.
• To delete a cookie, use the setcookie()
function with an expiration date in the
past.
Important Things About Cookies
• They are Small: Cookies are usually very small text files.
• They Have Names and Values: Each cookie has a name (to identify it) and a
value (the actual information being stored).
• They Can Expire: Cookies can have an expiration date. Some last only for your
current visit, while others can last for days, weeks, or even longer.
• You Can Manage Cookies: You can usually view, delete, and block cookies in
your web browser settings.
• Privacy Concerns: Sometimes, cookies are used for tracking your activity
across different websites, which can raise privacy concerns
Advantages of Cookies
• They remember you : Like a friendly face, a cookie can help a website recognize you when
you come back, so it can say "Welcome back!" and maybe even show you things you like.
• No need to log in again and again : If you log into a website, a cookie can remember that
you're logged in, so you don't have to type your username and password every single time you
visit.
• You get suggestions you might actually like : Cookies can help websites learn what you're
interested in and then suggest other things you might enjoy, like videos or articles.
• Websites can count how many visitors they have : Cookies help website owners see how
many people are visiting their site and which pages are popular. This helps them make the
website better for everyone.
• They can make websites faster to use : Sometimes, cookies can help websites load a little
quicker because they remember some information from your last visit.
• They help websites understand what's working and what's not : By seeing how people use
cookies, website owners can figure out what parts of their website are good and what they need
to improve.
References
• https://g.co/kgs/iSbTdzg
• https://www.kaspersky.com/resource-center/definitions/co
okies
• https://en.wikipedia.org/wiki/HTTP_cookie
• https://www.cloudflare.com/learning/privacy/what-are-coo
kies/
Thank you…