Slide 06 Client Side programming Javascript Cookies Ebusiness

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

Javascript • Java. Script = 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. • Java. Script 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) 2

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

Javascript • Learn MORE about HTML, CSS on the Internet and using slides here: http: //cs. newpaltz. edu/~phamh/aeb/slides E-business (constructed by Dr. Hanh Pham) 4

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) 5

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

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 email address … E-business (constructed by Dr. Hanh Pham) 7

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

Web Cookies Where are the web cookies? • In the “cookies. txt” or “cookies” FILE. Chrome: C: Documents and Settings<user name>Local SettingsApplication DataGoogleChromeUser DataDefault Cookies Or C: Users<User. Name>App. DataLocalGoogleChromeUser DataDefaultCookies Firefox: All the cookies are stored in "cookies. txt" at C: Documents and SettingsWindows login<User. Name>Application. DataMozillaFirefoxProfiles profile folder IE: C: Documents and Settings<User name>Local Settings E-business (constructed by Dr. Hanh Pham) 9

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

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

Javascript for Cookies <!DOCTYPE html> <head> <script> function set. Cookie(cname, cvalue, exdays) { var d = new Date(); d. set. Time(d. get. Time() + (exdays*24*60*60*1000)); var expires = "expires=" + d. to. GMTString(); document. cookie = cname+"="+cvalue+"; "+expires; } function check. Cookie() { var user=get. Cookie("username"); if (user != "") { alert("Welcome again " + user); } else { user = prompt("Please enter your name: ", ""); if (user != "" && user != null) { set. Cookie("username", user, 30); } } } </script> function get. Cookie(cname) { </head> var name = cname + "="; <body onload="check. Cookie()"> var ca = document. cookie. split('; '); </body> for(var i=0; i<ca. length; i++) { </html> var c = ca[i]; while (c. char. At(0)==' ') c = c. substring(1); if (c. index. Of(name) == 0) { return c. substring(name. length, c. length); } } return ""; E-business (constructed by Dr. Hanh Pham) } 12

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

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

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. Http. Only cookie: cookie will be used only when transmitting HTTP (or HTTPS) requests, thus restricting access from other, non-HTTP APIs such as Java. Script. 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, HTML 5 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) 15

Shopping Cart • Example, Demo, and Download: http: //html-cart. com/ E-business (constructed by Dr. Hanh Pham) 16

References Most of materials in this slide come from: • searchcio. techtarget. com • tutorialspoint. com • http: //jan. newmarch. name/ecommerce/session. html • http: //www. w 3 schools. com/ • http: //www. w 3. org/ • Many pictures here are downloaded from the Internet from various sites such as netbean. org, http: //people. cis. ksu. edu/~reshma, grin. com … • http: //www. allaboutcookies. org/cookies/ • Wikipedia • "Developing Distributed and E-commerce Applications", Darrel Ince, 2 nd Edition, Pearson Addison Wesley • “Web Programming and Internet Technologies: An E-commerce Approach”, Porter Scobey, Pawan Lingras, Jones • • • & Bartlett Publishers, 2013 “Electronic Commerce”, 11 th 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) 17
- Slides: 17