1 / 14

ECMM6018 Enterprise Networking for Electronic Commerce Tutorial 7

Learn about cookies in CGI/Perl, their definition and how they can be used to create more customizable web pages. Explore examples of sites that use cookies and the specifications and parameters involved in using cookies.

lkumar
Download Presentation

ECMM6018 Enterprise Networking for Electronic Commerce Tutorial 7

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ECMM6018Enterprise Networking for Electronic CommerceTutorial 7 CGI/Perl and Cookies

  2. Cookies • Definition: Information put on your computer’s hard disk by a website in the form of text files so that the website can remember the user at a later date • Cookies can be used to store information such as usernames, passwords or even send current weather and news for your particular region. In other words cookies can be used to help make more customizable web pages.

  3. Cookies • Can be used for purposes such as shopping carts (E-Commerce). • They can be written in a variety of languages including PERL, JavaScript, ASP, Cold Fusion and PHP. • Examples of sites that use cookies are Amazon, Payless

  4. Cookies • Only the Internet site that placed the cookie on your machine can read it • They are not programs • Specification of cookies • 1.A cookie may be no larger than 4k. • 2.There may be no more than 20 cookies per domain. 3.There may be no more than 300 cookies total from all sources. • Stored under the cookie directory in windows, if using MSIE • Stored in the cookies.txt file, if using Netscape

  5. Cookies • 6 parameters can be passed to it • 1. The name of the cookie (mandatory) • 2. The value of the cookie (mandatory) • 3. The expiration date of the cookie - if blank it will expire when the user closes the browser

  6. Cookies – Parameters ctd • 4. The path the cookie is valid for. • 5. The domain the cookie is valid for • 6. The need for a secure connection to exist to use the cookie. • The pieces of information are stored as name-value pairs • Each name-value pair is separated by a semi-colon

  7. How it all works • The URL of a Web site is entered into the browser, the browser sends a request to the Web site for the page. Your browser will contact Web site’s server and request its home page • When the browser does this, it will look on your machine for a cookie file that the Web site has set. If it finds an the Web site’s cookie file, the browser will send all of the name-value pairs in the file to the Web site’s server along with the URL. If it finds no cookie file, it will send no cookie data.

  8. How It Works - ctd • The Web site’s Web server receives the cookie data and the request for a page. If name-value pairs are received, the Web site can use them • If no name-value pairs are received, the Web site knows that you have not visited before. The server creates a new ID for you in the Web site’s database and then sends name-value pairs to your machine in the header for the Web page it sends. Your machine stores the name-value pairs on your hard disk. • The Web server can change name-value pairs or add new pairs whenever you visit the site and request a page.

  9. Example • Cookie being sent from the server to the browser Content-type: text/html Set-Cookie: foo=bar; path=/; expires Mon, 09-Dec-2002 13:46:00 GMT • Cookie being sent from the browser to the server Content-type: text/html Cookie: foo=bar

  10. Perl and Cookies • CGI scripts create one or more cookies and send them to the browser in the HTTP header. • Browser returns the cookies to the CGI script during subsequent interactions • Interface to cookies by using the cookie method()

  11. Cookie Method • Create an object of type CGI and assign it to a variable E.g. $cgiobject=new CGI; $cookie = $cgiobject->cookie(-name=>'sessionID', -value=>\%cookie_data, -expires=>'+1h', -path=>'/cgi-bin/database', -domain=>'.capricorn.org', -secure=>1);

  12. Sending Cookies through HTTP • The cookie created by cookie() method must be incorporated into the HTTP header • E.g. print $cgiobject->header(-cookie=>$cookie); • It is possible to send multiple cookies in the HTTP header • print $cgiobject->header(-cookie=>[$cookie1,$cookie2]);

  13. Retrieving Cookies • To retrieve a cookie, request it by name by calling cookie() method with the name parameter • E.g. cookie_data=$cgiobject->cookie(“sessionID");

  14. Useful Links • http://stein.cshl.org/WWW/software/CGI/cgi_docs.html#cookies • http://www.cookiecentral.com • http://www.katsueydesignworks.com/cgi_cookies.htm

More Related