SlideShare a Scribd company logo
2
Most read
3
Most read
8
Most read
Java Cookies
By
Rajanivetha G
Contents
• What’s a Cookie!
• Types of Cookie
• Cookie parameters
• JavaScript Cookie
• Creating a Cookie
• Reading, Changing and Deleting a Cookie
• The Cookie string
• Set a Cookie
• Get a Cookie
• Check a Cookie
What’s a Cookie!
• It is a file residing on your web browser
• Stores user info from a website
• Updated via HTML
• Queried via JavaScript
Types of Cookie
• Session cookie
• Persistent cookie
• Malicious cookie
Cookie parameters
• The name of the cookie
• The value of the cookie
• The expiration date of the cookie
• The path the cookie is valid for
• The domain the cookie is valid for
• The need for a secure connection
JavaScript Cookie
• Initially a visitor fills in his name
• Name is saved
• Welcome message is displayed at his next visit
• A JavaScript can create, delete and read cookies
• A JavaScript program checks the cookie file
• It queries the user
– E.g.: username=“John Doe”;
Create a Cookie
– document.cookie="username=John Doe";
• Expiry date:
– document.cookie="username=John Doe;
expires=Thu, 18 Dec 2013 12:00:00 UTC";
• Cookie path:
– document.cookie="username=John Doe;
expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/";
Reading , Changing and Deleting a Cookie
• Read:
– var x = document.cookie;
• Change:
– document.cookie="username=John Doe";
– document.cookie="username=John Smith;
expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/";
• Delete:
– document.cookie = "username=; expires=Thu, 01
Jan 1970 00:00:00 UTC";
The Cookie String
– Document.cookie=cookie1,cookie2……..
• New cookies are created over and over
• Cookie1=value; cookie2=value;……..
• function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1);
if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
}
return "";
}
function checkCookie() {
var user = getCookie("username");
if (user != "") {
alert("Welcome again " + user);
} else {
user = prompt("Please enter your name:", "");
if (user != "" && user != null) {
setCookie("username", user, 365);
}
}
}
A Function to set a Cookie
• function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() +
(exdays*24*60*60*1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue +
"; " + expires;
}
A Function to Get a Cookie
• function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1);
if (c.indexOf(name) == 0) return
c.substring(name.length,c.length);
}
return "";
}
A Function to Check a Cookie
• function checkCookie() {
var username=getCookie("username");
if (username!="") {
alert("Welcome again " + username);
}else{
username = prompt("Please enter your name:", "");
if (username != "" && username != null) {
setCookie("username", username, 365);
}
}
}
java Cookies

More Related Content

PPTX
Java servlets
PPT
Paging.ppt
PDF
Code optimization in compiler design
PPTX
Directed Acyclic Graph Representation of basic blocks
PPT
Minimization of DFA
PPTX
Introduction TO Finite Automata
PPTX
Types of Drivers in JDBC
PPT
Cookies in servlet
Java servlets
Paging.ppt
Code optimization in compiler design
Directed Acyclic Graph Representation of basic blocks
Minimization of DFA
Introduction TO Finite Automata
Types of Drivers in JDBC
Cookies in servlet

What's hot (20)

PPT
Operating Systems - "Chapter 5 Process Synchronization"
PPTX
Principle source of optimazation
PPT
Loaders
PPTX
Java awt (abstract window toolkit)
PPTX
MACRO PROCESSOR
PPTX
Synchronization hardware
PPTX
Video display devices
PPTX
Deadlock dbms
PDF
JavaScript - Chapter 12 - Document Object Model
PPTX
Dag representation of basic blocks
PPT
Files and Directories in PHP
PPTX
JAVA AWT
PPTX
Distance Vector & Link state Routing Algorithm
PPT
Sliding window protocol
PDF
IT2255 Web Essentials - Unit I Website Basics
PPTX
Association Rule mining
PDF
Android notification
PDF
Run time storage
PPTX
Tcp/ip server sockets
PPSX
Functional dependency
Operating Systems - "Chapter 5 Process Synchronization"
Principle source of optimazation
Loaders
Java awt (abstract window toolkit)
MACRO PROCESSOR
Synchronization hardware
Video display devices
Deadlock dbms
JavaScript - Chapter 12 - Document Object Model
Dag representation of basic blocks
Files and Directories in PHP
JAVA AWT
Distance Vector & Link state Routing Algorithm
Sliding window protocol
IT2255 Web Essentials - Unit I Website Basics
Association Rule mining
Android notification
Run time storage
Tcp/ip server sockets
Functional dependency
Ad

Viewers also liked (15)

PPT
Fisrt tes
PDF
Token statt Cookies dank JWT (Java Land 2016)
PPTX
Cookie management
PPT
Java Security And Authentacation
PDF
Java session 3
PPTX
Cookies: HTTP state management mechanism
PDF
Secure Authentication and Session Management in Java EE
PPT
PPSX
Sessions and cookies
PPTX
Advance Java Topics (J2EE)
PPTX
Cookie and session
PPT
Java Servlets
PPT
Presentation on Internet Cookies
PDF
Customer relationship management in Hotel Industry
PPTX
Customer Relationship Management (CRM): Theory and Practice
Fisrt tes
Token statt Cookies dank JWT (Java Land 2016)
Cookie management
Java Security And Authentacation
Java session 3
Cookies: HTTP state management mechanism
Secure Authentication and Session Management in Java EE
Sessions and cookies
Advance Java Topics (J2EE)
Cookie and session
Java Servlets
Presentation on Internet Cookies
Customer relationship management in Hotel Industry
Customer Relationship Management (CRM): Theory and Practice
Ad

Similar to java Cookies (20)

PPTX
PHP COOKIES AND SESSIONS
PPTX
Php cookies
PPTX
javaScriptCookies.pptx
PPT
16 cookies
PDF
F2e security
PDF
07 cookies
PPTX
19_JavaScript - Storage_Cookies_students.pptx
PPTX
19_JavaScript - Storage_Cookies-tutorial .pptx
PPTX
Cookie Attribute.pptx
PPTX
Ch4(saving state with cookies and query strings)
PPTX
Cookies
PPTX
Advance java session 7
PPT
Cookies in php lecture 2
PDF
ASP.NET-Web Programming - Sessions and Cookies
PPTX
Php Basics part 1
PPT
Cookies and sessions
PDF
Google cloud storage 講個祕訣
PPT
PHP - Getting good with cookies
PPTX
Cookies
KEY
Plone Interactivity
PHP COOKIES AND SESSIONS
Php cookies
javaScriptCookies.pptx
16 cookies
F2e security
07 cookies
19_JavaScript - Storage_Cookies_students.pptx
19_JavaScript - Storage_Cookies-tutorial .pptx
Cookie Attribute.pptx
Ch4(saving state with cookies and query strings)
Cookies
Advance java session 7
Cookies in php lecture 2
ASP.NET-Web Programming - Sessions and Cookies
Php Basics part 1
Cookies and sessions
Google cloud storage 講個祕訣
PHP - Getting good with cookies
Cookies
Plone Interactivity

More from Rajanivetha G (9)

PPT
Input devices
PPTX
Human, object detection
PPTX
Modelling the driving behaviour of e-vehicles
PPTX
Java ring
PPTX
PPTX
PPTX
30 st.mary axe
PPT
Google glasses
PPTX
Artificial intelligence in speech recognition
Input devices
Human, object detection
Modelling the driving behaviour of e-vehicles
Java ring
30 st.mary axe
Google glasses
Artificial intelligence in speech recognition

Recently uploaded (20)

PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
RMMM.pdf make it easy to upload and study
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Sports Quiz easy sports quiz sports quiz
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Insiders guide to clinical Medicine.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Lesson notes of climatology university.
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
Cell Structure & Organelles in detailed.
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Complications of Minimal Access Surgery at WLH
PPTX
PPH.pptx obstetrics and gynecology in nursing
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
RMMM.pdf make it easy to upload and study
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Sports Quiz easy sports quiz sports quiz
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
human mycosis Human fungal infections are called human mycosis..pptx
Insiders guide to clinical Medicine.pdf
Final Presentation General Medicine 03-08-2024.pptx
Anesthesia in Laparoscopic Surgery in India
Abdominal Access Techniques with Prof. Dr. R K Mishra
Lesson notes of climatology university.
2.FourierTransform-ShortQuestionswithAnswers.pdf
Cell Structure & Organelles in detailed.
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Microbial diseases, their pathogenesis and prophylaxis
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Complications of Minimal Access Surgery at WLH
PPH.pptx obstetrics and gynecology in nursing

java Cookies

  • 2. Contents • What’s a Cookie! • Types of Cookie • Cookie parameters • JavaScript Cookie • Creating a Cookie • Reading, Changing and Deleting a Cookie • The Cookie string • Set a Cookie • Get a Cookie • Check a Cookie
  • 3. What’s a Cookie! • It is a file residing on your web browser • Stores user info from a website • Updated via HTML • Queried via JavaScript
  • 4. Types of Cookie • Session cookie • Persistent cookie • Malicious cookie
  • 5. Cookie parameters • The name of the cookie • The value of the cookie • The expiration date of the cookie • The path the cookie is valid for • The domain the cookie is valid for • The need for a secure connection
  • 6. JavaScript Cookie • Initially a visitor fills in his name • Name is saved • Welcome message is displayed at his next visit • A JavaScript can create, delete and read cookies • A JavaScript program checks the cookie file • It queries the user – E.g.: username=“John Doe”;
  • 7. Create a Cookie – document.cookie="username=John Doe"; • Expiry date: – document.cookie="username=John Doe; expires=Thu, 18 Dec 2013 12:00:00 UTC"; • Cookie path: – document.cookie="username=John Doe; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/";
  • 8. Reading , Changing and Deleting a Cookie • Read: – var x = document.cookie; • Change: – document.cookie="username=John Doe"; – document.cookie="username=John Smith; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/"; • Delete: – document.cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
  • 9. The Cookie String – Document.cookie=cookie1,cookie2…….. • New cookies are created over and over • Cookie1=value; cookie2=value;……..
  • 10. • function setCookie(cname, cvalue, exdays) { var d = new Date(); d.setTime(d.getTime() + (exdays*24*60*60*1000)); var expires = "expires="+d.toUTCString(); document.cookie = cname + "=" + cvalue + "; " + expires; } function getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for(var i=0; i<ca.length; i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1); if (c.indexOf(name) == 0) return c.substring(name.length, c.length); } return ""; } function checkCookie() { var user = getCookie("username"); if (user != "") { alert("Welcome again " + user); } else { user = prompt("Please enter your name:", ""); if (user != "" && user != null) { setCookie("username", user, 365); } } }
  • 11. A Function to set a Cookie • function setCookie(cname, cvalue, exdays) { var d = new Date(); d.setTime(d.getTime() + (exdays*24*60*60*1000)); var expires = "expires="+d.toUTCString(); document.cookie = cname + "=" + cvalue + "; " + expires; }
  • 12. A Function to Get a Cookie • function getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for(var i=0; i<ca.length; i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1); if (c.indexOf(name) == 0) return c.substring(name.length,c.length); } return ""; }
  • 13. A Function to Check a Cookie • function checkCookie() { var username=getCookie("username"); if (username!="") { alert("Welcome again " + username); }else{ username = prompt("Please enter your name:", ""); if (username != "" && username != null) { setCookie("username", username, 365); } } }