General |  Social Media |  Miscellaneous
srcraft blog logo
  • Business
  • News
  • Shopping
  • Travel
  • Disease
  • Pets
  • Life
  • Health
  • Technology
  • Category
  • Contact Us
Latest Blog : 
☛ Crystal Resort and Lawns: Premier Hotel Accommodation in Hoshangabad ☛ Insights from My Experience at a Dodge City Meatpacking Plant ☛ Advancements in Sleep Science: Understanding Rest in the Modern Age ☛ New High-Value Cash Back Credit Cards Enter the Market ☛ Exploring the Health Benefits of Coffee ☛ The Impact of Climate Change on Wine Country ☛ One Man, One Dog, and a Journey Across the Globe ☛ Major Airliner Accidents and Incidents in India: A Historical Overview ☛ Boeing 787 Dreamliner: Innovation, Efficiency, and the Future of Air Travel ☛ Air India Ahmedabad Crash: Flight AI-171 
Home > Innovation & Technology > PHP

How to set cookies in php


how to set cookies in php

Cookies are the small text file that is stored on the client local computer. When client computer requests a page with a browser, then it sends the cookies data to the web server that is reduce the server response time. In PHP, you can create, retrieve and delete cookie values both.

Here, there are 3 steps to identify users by cookies:

  1. Server sends a set of cookies to the client local browser like user name, city, pin code etc.
  2. Client browser stores cookies data on local system when web server sends first time cookies data.
  3. In future, when browser sends any request to the server then it sends all cookies data to the server and server uses that data to identify the unique user.

How to set cookies with PHP?

For set cookies, we will use setcookie() function.

Syntax:

setcookie(name, value, expire, path, domain, secure);

Note: On above syntax, only name parameter is required and all other parameters are optional.

Below is detail of all parameter:

  1. Name: This is a required parameter. It is the name of the cookie and it is stored in an environment variable that is called HTTP_COOKIE_VARS.
  2. Value: This is the content of name parameter that is actually stores for future use.
  3. Expiry: This is the time limitation of cookies. If you will not set expiry, it will automatically expire when browser is closed.
  4. Path: This is a directory for which the cookie is valid. The single forward slash means that the cookie is available in the entire website.
  5. Domain: All cookies are only valid for the specific domain name.
  6. Security: This shows, way of cookies either HTTPS or HTTP. If cookie is set to 1 then it will send to HTTPS otherwise it will send by regular HTTP.

Note: The setcookie() function must use BEFORE the starting oftag.

The following example creates a cookie that name is "sr" with the value "srcraft india". The following cookie will expire after 10 days (86400 * 10).

Note: 86400 means one day.

 

 

 

 

 

 

 

 

 

How to modify a Cookie value?

For modify a cookie, There are no another way. We have to set again cookie using the setcookie() function.

 

 

 

 

 

 

 

 

 

How to delete a Cookie?

 

 

 

 

 

 

 

 

 

How to check cookies are enabled or not?

Before checking cookies are enabled or not, we have to set cookies. After that we have to count the $_COOKIE array variable

 

 

 

 

 

 

For more, visit:  how to set cookies in php

Written By: Charles Miller Published in PHP


Search

Publish your passions on srcraftblog.com

Latest Post

☛ Crystal Resort and Lawns: Premier Hotel Accommodation in Hoshangabad

☛ Insights from My Experience at a Dodge City Meatpacking Plant

☛ Advancements in Sleep Science: Understanding Rest in the Modern Age

☛ New High-Value Cash Back Credit Cards Enter the Market

☛ Exploring the Health Benefits of Coffee

☛ The Impact of Climate Change on Wine Country

☛ One Man, One Dog, and a Journey Across the Globe

☛ Major Airliner Accidents and Incidents in India: A Historical Overview

☛ Boeing 787 Dreamliner: Innovation, Efficiency, and the Future of Air Travel

☛ Air India Ahmedabad Crash: Flight AI-171


We are accepting well-written informative Guest Posts on srcraftblog.com

Innovation & Technology

Artificial Intelligent blogs
Cryptocurrency blogs
Digital India blogs
Data science blogs
Neuroscience blogs
Programming blogs

Physical science

Physics blogs
Chemistry blogs
Earth science blogs
Geology blogs
Oceanography blogs
Meteorology blogs

Industry

Business blogs
Economy blogs
Freelancing blogs
Leadership blogs
Productivity blogs
Work blogs

Society

Basic income blogs
Education blogs
Environment blogs
Media blogs
Philosophy blogs
Women blogs
About us |  Write for us |  Terms and conditions |  Privacy Policy |  Our Services |  Contact us

© 2025 SRCRAFT INIDA