SlideShare une entreprise Scribd logo
1  sur  9
Aruna Devi P.
Assistant Professor
Department of Computer Science(SF)
V.V.V. College for Women
Cookies
 Small File – Max size 4KB
 Stored on client
 Used for tracking user information
 Could be retrieved to personalize the page when users
visit for next time.
 Could be read by the domain which sets the cookie
Setting Cookie
 Setting of cookie could be done with
 setcookie() function
 header() function
 This function should be used before any output is
generated from the script
 Otherwise Cookie will not be set
Syntax for Cookie
 setcookie(Name, Value, Expire, Path, Domain, Security)
 Name: It is used to set the name of the cookie.
 Value: It is used to set the value of the cookie.
 Expire: It is used to set the expiry timestamp of the cookie
after which the cookie can’t be accessed.
 Path: It is used to specify the path on the server for which
the cookie will be available.
 Domain: It is used to specify the domain for which the
cookie is available.
 Security: It is used to indicate that the cookie should be
sent only if a secure HTTPS connection exists.
Example
 setcookie(“Product”, ”Car”, time()+3600, “/”,
“.yourdomain.com”,0)
 Ist two parameter is the name and value of the cookie
 Next is the time() which retrieves the current time, when we
add 3600 sec the expiry time will be one hour from the cookie
setting
 / says the cookie could be retrieved from any page within the
server environment.
 Domain is the site which we are working, if left blank then it
would be considered as localhost
 Last argument is for transmitting cookie in secure or unsecure
environment (Secure =1, unsecure =0).
header() function
 header(“Set-Cookie: Product = Car;
expires = Thu, 12-Dec-19 12:30: 59 GMT;
path=/;
domain=yourdomain.com”);
This method is difficult since we have to create a header
string.
Time is mentioned in Unix epoch format.
Checking the setting of cookie
 isset() is used whether a cookie has been set
 $_COOKIE is the superglobal for retrieving the cookie
value.
 isset($_COOKIE[“cookiename”])
 Returns true if the cookiename specified is set
 Returns false if the cookiename is not set
 To print the value of the cookie
 echo “Cookie value is : “.$_COOKIE[“cookiename”]
Deleting a Cookie
 Could be deleted in two ways
 Using setcookie() is called with the name of cookie
 setcookie(“cookiename”)
 Change the timestamp to the time that already expired.
 setcookie(“cookiename”, “”,time()-60,”/”,domain,0)
Thank you

Contenu connexe

Tendances

Distributed in memory data grid
Distributed in memory data gridDistributed in memory data grid
Distributed in memory data grid
Alexander Albul
 
DUMP-2013 Serverside - О хранилище “Зебра” - Казаков Александр
DUMP-2013 Serverside - О хранилище “Зебра” - Казаков АлександрDUMP-2013 Serverside - О хранилище “Зебра” - Казаков Александр
DUMP-2013 Serverside - О хранилище “Зебра” - Казаков Александр
it-people
 

Tendances (20)

利用Init connect做mysql clients stat 用户审计
 利用Init connect做mysql clients stat 用户审计 利用Init connect做mysql clients stat 用户审计
利用Init connect做mysql clients stat 用户审计
 
Intro KaKao MRTE (MySQL Realtime Traffic Emulator)
Intro KaKao MRTE (MySQL Realtime Traffic Emulator)Intro KaKao MRTE (MySQL Realtime Traffic Emulator)
Intro KaKao MRTE (MySQL Realtime Traffic Emulator)
 
MySQL Slow Query log Monitoring using Beats & ELK
MySQL Slow Query log Monitoring using Beats & ELKMySQL Slow Query log Monitoring using Beats & ELK
MySQL Slow Query log Monitoring using Beats & ELK
 
MySQL flexible schema and JSON for Internet of Things
MySQL flexible schema and JSON for Internet of ThingsMySQL flexible schema and JSON for Internet of Things
MySQL flexible schema and JSON for Internet of Things
 
ClickHouse and the Magic of Materialized Views, By Robert Hodges and Altinity...
ClickHouse and the Magic of Materialized Views, By Robert Hodges and Altinity...ClickHouse and the Magic of Materialized Views, By Robert Hodges and Altinity...
ClickHouse and the Magic of Materialized Views, By Robert Hodges and Altinity...
 
Sol2
Sol2Sol2
Sol2
 
Distributed in memory data grid
Distributed in memory data gridDistributed in memory data grid
Distributed in memory data grid
 
DUMP-2013 Serverside - О хранилище “Зебра” - Казаков Александр
DUMP-2013 Serverside - О хранилище “Зебра” - Казаков АлександрDUMP-2013 Serverside - О хранилище “Зебра” - Казаков Александр
DUMP-2013 Serverside - О хранилище “Зебра” - Казаков Александр
 
Weather of the Century: Design and Performance
Weather of the Century: Design and PerformanceWeather of the Century: Design and Performance
Weather of the Century: Design and Performance
 
Building ClickHouse and Making Your First Contribution: A Tutorial_06.10.2021
Building ClickHouse and Making Your First Contribution: A Tutorial_06.10.2021Building ClickHouse and Making Your First Contribution: A Tutorial_06.10.2021
Building ClickHouse and Making Your First Contribution: A Tutorial_06.10.2021
 
Tricks every ClickHouse designer should know, by Robert Hodges, Altinity CEO
Tricks every ClickHouse designer should know, by Robert Hodges, Altinity CEOTricks every ClickHouse designer should know, by Robert Hodges, Altinity CEO
Tricks every ClickHouse designer should know, by Robert Hodges, Altinity CEO
 
Python my SQL - create table
Python my SQL - create tablePython my SQL - create table
Python my SQL - create table
 
Creating Beautiful Dashboards with Grafana and ClickHouse
Creating Beautiful Dashboards with Grafana and ClickHouseCreating Beautiful Dashboards with Grafana and ClickHouse
Creating Beautiful Dashboards with Grafana and ClickHouse
 
Python my sql database connection
Python my sql   database connectionPython my sql   database connection
Python my sql database connection
 
Webinar slides: Adding Fast Analytics to MySQL Applications with Clickhouse
Webinar slides: Adding Fast Analytics to MySQL Applications with ClickhouseWebinar slides: Adding Fast Analytics to MySQL Applications with Clickhouse
Webinar slides: Adding Fast Analytics to MySQL Applications with Clickhouse
 
ClickHouse materialized views - a secret weapon for high performance analytic...
ClickHouse materialized views - a secret weapon for high performance analytic...ClickHouse materialized views - a secret weapon for high performance analytic...
ClickHouse materialized views - a secret weapon for high performance analytic...
 
MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...
MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...
MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...
 
A Practical Introduction to Handling Log Data in ClickHouse, by Robert Hodges...
A Practical Introduction to Handling Log Data in ClickHouse, by Robert Hodges...A Practical Introduction to Handling Log Data in ClickHouse, by Robert Hodges...
A Practical Introduction to Handling Log Data in ClickHouse, by Robert Hodges...
 
Rental
RentalRental
Rental
 
AJUG April 2011 Raw hadoop example
AJUG April 2011 Raw hadoop exampleAJUG April 2011 Raw hadoop example
AJUG April 2011 Raw hadoop example
 

Similaire à Cookies in php

Web app development_cookies_sessions_14
Web app development_cookies_sessions_14Web app development_cookies_sessions_14
Web app development_cookies_sessions_14
Hassen Poreya
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
salissal
 

Similaire à Cookies in php (20)

Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
 
Web app development_cookies_sessions_14
Web app development_cookies_sessions_14Web app development_cookies_sessions_14
Web app development_cookies_sessions_14
 
Sessions and cookies
Sessions and cookiesSessions and cookies
Sessions and cookies
 
Lecture 11 - PHP - Part 5 - CookiesSessions.ppt
Lecture 11 - PHP - Part 5 - CookiesSessions.pptLecture 11 - PHP - Part 5 - CookiesSessions.ppt
Lecture 11 - PHP - Part 5 - CookiesSessions.ppt
 
4 php-advanced
4 php-advanced4 php-advanced
4 php-advanced
 
JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)
 
Cookies
CookiesCookies
Cookies
 
PHP-Cookies-Sessions.pdf
PHP-Cookies-Sessions.pdfPHP-Cookies-Sessions.pdf
PHP-Cookies-Sessions.pdf
 
4.4 PHP Session
4.4 PHP Session4.4 PHP Session
4.4 PHP Session
 
Cookie and session
Cookie and sessionCookie and session
Cookie and session
 
Cookies-PHP
Cookies-PHPCookies-PHP
Cookies-PHP
 
javaScriptCookies.pptx
javaScriptCookies.pptxjavaScriptCookies.pptx
javaScriptCookies.pptx
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
 
Cookies
CookiesCookies
Cookies
 
Cookies & Session
Cookies & SessionCookies & Session
Cookies & Session
 
cookies.ppt
cookies.pptcookies.ppt
cookies.ppt
 
Manish
ManishManish
Manish
 
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 202010 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
 
Lecture8 php page control by okello erick
Lecture8 php page control by okello erickLecture8 php page control by okello erick
Lecture8 php page control by okello erick
 
PHP with MYSQL
PHP with MYSQLPHP with MYSQL
PHP with MYSQL
 

Plus de ArunaDevi63 (8)

FuzzySet.pptx
FuzzySet.pptxFuzzySet.pptx
FuzzySet.pptx
 
Instructioncycle.ppt
Instructioncycle.pptInstructioncycle.ppt
Instructioncycle.ppt
 
Asynchronous Data Transfer.pptx
Asynchronous Data Transfer.pptxAsynchronous Data Transfer.pptx
Asynchronous Data Transfer.pptx
 
Mf formulation and parameterization
Mf formulation and parameterizationMf formulation and parameterization
Mf formulation and parameterization
 
Soft Computing
Soft ComputingSoft Computing
Soft Computing
 
Laws of boolean algebra
Laws of boolean algebraLaws of boolean algebra
Laws of boolean algebra
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Computer Organisation - Addressing Modes
Computer Organisation - Addressing ModesComputer Organisation - Addressing Modes
Computer Organisation - Addressing Modes
 

Dernier

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Krashi Coaching
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 

Dernier (20)

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 

Cookies in php

  • 1. Aruna Devi P. Assistant Professor Department of Computer Science(SF) V.V.V. College for Women
  • 2. Cookies  Small File – Max size 4KB  Stored on client  Used for tracking user information  Could be retrieved to personalize the page when users visit for next time.  Could be read by the domain which sets the cookie
  • 3. Setting Cookie  Setting of cookie could be done with  setcookie() function  header() function  This function should be used before any output is generated from the script  Otherwise Cookie will not be set
  • 4. Syntax for Cookie  setcookie(Name, Value, Expire, Path, Domain, Security)  Name: It is used to set the name of the cookie.  Value: It is used to set the value of the cookie.  Expire: It is used to set the expiry timestamp of the cookie after which the cookie can’t be accessed.  Path: It is used to specify the path on the server for which the cookie will be available.  Domain: It is used to specify the domain for which the cookie is available.  Security: It is used to indicate that the cookie should be sent only if a secure HTTPS connection exists.
  • 5. Example  setcookie(“Product”, ”Car”, time()+3600, “/”, “.yourdomain.com”,0)  Ist two parameter is the name and value of the cookie  Next is the time() which retrieves the current time, when we add 3600 sec the expiry time will be one hour from the cookie setting  / says the cookie could be retrieved from any page within the server environment.  Domain is the site which we are working, if left blank then it would be considered as localhost  Last argument is for transmitting cookie in secure or unsecure environment (Secure =1, unsecure =0).
  • 6. header() function  header(“Set-Cookie: Product = Car; expires = Thu, 12-Dec-19 12:30: 59 GMT; path=/; domain=yourdomain.com”); This method is difficult since we have to create a header string. Time is mentioned in Unix epoch format.
  • 7. Checking the setting of cookie  isset() is used whether a cookie has been set  $_COOKIE is the superglobal for retrieving the cookie value.  isset($_COOKIE[“cookiename”])  Returns true if the cookiename specified is set  Returns false if the cookiename is not set  To print the value of the cookie  echo “Cookie value is : “.$_COOKIE[“cookiename”]
  • 8. Deleting a Cookie  Could be deleted in two ways  Using setcookie() is called with the name of cookie  setcookie(“cookiename”)  Change the timestamp to the time that already expired.  setcookie(“cookiename”, “”,time()-60,”/”,domain,0)