Presentation is loading. Please wait.

Presentation is loading. Please wait.

Client Side programming: Javascript, Cookies

Similar presentations


Presentation on theme: "Client Side programming: Javascript, Cookies"— Presentation transcript:

1 Client Side programming: Javascript, Cookies
Slide # 06 Client Side programming: Javascript, Cookies E-business (constructed by Dr. Hanh Pham)

2 E-business (constructed by Dr. Hanh Pham)
Javascript JavaScript = programming language mostly used within web browsers (web client), to create web pages which can interact with the users to input data and output /change result (on the web page). Rarely it can be used in server-side network programming with Node.js, game development and the creation of desktop and mobile applications. JavaScript is also used in environments that aren't web-based, such as PDF documents, site-specific browsers, and desktop widgets. E-business (constructed by Dr. Hanh Pham)

3 Javascript with HTML & CSS
E-business (constructed by Dr. Hanh Pham)

4 E-business (constructed by Dr. Hanh Pham)
Javascript Learn MORE about HTML, CSS on the Internet and using slides here: E-business (constructed by Dr. Hanh Pham)

5 E-business (constructed by Dr. Hanh Pham)
Web Cookies What IS a web cookie? A web cookie is a small text file from a website are stored on client's browser directory. What is IN a web cookie? URL(domain name) of the website that created the cookie Name of the cookie Content: (coded) string (as your ID) Dates: creation and expiration E-business (constructed by Dr. Hanh Pham)

6 E-business (constructed by Dr. Hanh Pham)
Cookies E-business (constructed by Dr. Hanh Pham)

7 E-business (constructed by Dr. Hanh Pham)
Web Cookies PURPOSE of web cookies Session management (shopping cart) Personalization (login, recognize users) Tracking (to keep track of your movements) HOW ? The website stores a text/cookie with an ID(string) at your browser (client side). The website stores a corresponding file/data(with same ID)to the one they set in your browser(text/cookie). In this file they can record your movements and other information such as address … E-business (constructed by Dr. Hanh Pham)

8 E-business (constructed by Dr. Hanh Pham)
Cookies E-business (constructed by Dr. Hanh Pham)

9 E-business (constructed by Dr. Hanh Pham)
Web Cookies Where are the web cookies? In the “cookies.txt” or “cookies” FILE. Chrome: C:\Documents and Settings\<user name>\Local Settings\Application Data\Google\Chrome\User Data\Default\ Cookies Or C:\Users\<UserName>\AppData\Local\Google\Chrome\User Data\Default\Cookies Firefox: All the cookies are stored in "cookies.txt" at C:\Documents and Settings\Windows login\<UserName>\ApplicationData\Mozilla\Firefox\Profiles\ profile folder IE: C:\Documents and Settings\<User name>\Local Settings E-business (constructed by Dr. Hanh Pham)

10 E-business (constructed by Dr. Hanh Pham)
Cookies E-business (constructed by Dr. Hanh Pham)

11 E-business (constructed by Dr. Hanh Pham)
Setup a Cookie E-business (constructed by Dr. Hanh Pham)

12 Javascript for Cookies
<!DOCTYPE html> <html> function checkCookie() { <head> var user=getCookie("username"); <script> if (user != "") { alert("Welcome again " + user); function setCookie(cname,cvalue,exdays) { } else { var d = new Date(); user = prompt("Please enter your name:",""); d.setTime(d.getTime() + (exdays*24*60*60*1000)); if (user != "" && user != null) { setCookie("username", user, 30); var expires = "expires=" + d.toGMTString(); document.cookie = cname+"="+cvalue+"; "+expires; } </script> function getCookie(cname) { </head> var name = cname + "="; <body onload="checkCookie()"> var ca = document.cookie.split(';'); </body> for(var i=0; i<ca.length; i++) { </html> 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 ""; E-business (constructed by Dr. Hanh Pham)

13 1st Time: setCookie(username)
E-business (constructed by Dr. Hanh Pham)

14 2nd Time: getCookie(cname)
E-business (constructed by Dr. Hanh Pham)

15 E-business (constructed by Dr. Hanh Pham)
Types of Web Cookies Session cookie: in-memory cookie or transient cookie, exists only in temporary memory while the user navigates the website. Persistent cookie: is stored until expiration date, often used as tracking cookies. Secure cookie: cookie is always encrypted when transmitting from client to server. This makes the cookie less likely to be exposed to cookie theft via eavesdropping. HttpOnly cookie: cookie will be used only when transmitting HTTP (or HTTPS) requests, thus restricting access from other, non-HTTP APIs such as JavaScript. Third-party cookie: cookies that belong to domains different from the one shown in the address bar. Web pages can feature content from third-party domains (such as banner ads), which opens up the potential for tracking the user's browsing history. Supercookie: a cookie with an origin of a Top-Level Domain (such as .com) or a Public Suffix (such as .co.uk). It is important that supercookies are blocked by browsers, due to the security holes they introduce. This can be used to fake logins or change user information. Zombie cookie: cookies are automatically recreated after a user has deleted them; This is accomplished by a script storing the content of the cookie in some other locations, such as the local storage available to Flash content, HTML5 storages and other client-side mechanisms, and then recreating the cookie from backup stores when the cookie's absence is detected. E-business (constructed by Dr. Hanh Pham)

16 E-business (constructed by Dr. Hanh Pham)
Shopping Cart Example, Demo, and Download: E-business (constructed by Dr. Hanh Pham)

17 E-business (constructed by Dr. Hanh Pham)
References Most of materials in this slide come from: searchcio.techtarget.com tutorialspoint.com Many pictures here are downloaded from the Internet from various sites such as netbean.org, grin.com … Wikipedia "Developing Distributed and E-commerce Applications", Darrel Ince, 2nd Edition, Pearson Addison Wesley “Web Programming and Internet Technologies: An E-commerce Approach”, Porter Scobey, Pawan Lingras, Jones & Bartlett Publishers, 2013 “Electronic Commerce”, 11th Edition, Cengage Learning, Gary Schneider, 2015 Internet & World Wide Web How to Program, 5/e, Paul J. Deitel, Harvey M. Deitel, Abbey Deitel Introduction to Electronic Commerce, 3/E, Efraim Turban, David King, Judy Lang, Pearson, 2011 E-business (constructed by Dr. Hanh Pham)


Download ppt "Client Side programming: Javascript, Cookies"

Similar presentations


Ads by Google