Presentation is loading. Please wait.

Presentation is loading. Please wait.

CGI II: Cookies & Stuff Web Programming.

Similar presentations


Presentation on theme: "CGI II: Cookies & Stuff Web Programming."— Presentation transcript:

1 CGI II: Cookies & Stuff Web Programming

2 HTTP Cookie Mechanism to store/retrieve information on the HTTP client
Web server sends a “cookie” in HTTP response header cookie is stored as text file (not executable) on the client’s local drive cookie is included in subsequent HTTP request headers until expiration Syntax HTTP Response Cookie is created & sent from Web Server to Web Client (e.g., Internet Explorer) Set-Cookie: NAME=VALUE; expires=DATE; domain=DOMAIN_NAME; path=PATH e.g. Set-Cookie: user=kiyang; expires=Thursday, 09-Dec-10 11:11:22 GMT; domain= kiyang.kmu.ac.kr; path=/~kiyang/teaching HTTP Request Cookie is returned from Web Client to Web Server Cookie: NAME1=VALUE1; NAME2=VALUE2; .. e.g. Cookie: user=kiyang; Web Programming

3 Cookies with CGI.pm Setting Cookies Getting Cookies
$cookie = cookie ( -name => “WP-cookie”, -value => “$cookieID”, -path=> “/teaching/WP/f10’, -expires=>’+24h’); print header (-cookie=>$cookie); Getting Cookies $cookie_value = cookie (‘cookie-name’);  Example: Form Form CGI CGI (sending cookie) CGI (checking cookie) Web Programming

4 Fetching Web Pages Using LWP::Simple #!/usr/bin/perl use LWP::Simple;
$url= $body= get($url); print $body; Example script Web Programming

5 Fetching Web Pages Using WWW-Mechanize
use WWW::Mechanize; $url= " # Create a mechanize object my $mech = WWW::Mechanize->new( autocheck => 1 ); # Fetch a page $mech->get($url); print $mech->content; # Fetch a page into a file $mech->get($url,":content_file"=>"hello.htm"); # Get links @links= $mech->links(); array of link object foreach { my($url,$text,$absurl)= ($link->url(), $link->text, $link->url_abs()); print “$url, $text, $absurl\n”; } # Find links $link= $mech->find_link(url_abs_regex=>qr|^ $page= $mech->follow_link(url_abs_regex=>qr|^ @pages= $mech->follow_all_links(url_abs_regex=>qr|^ Mechanized Spider Example: HTML, CGI S517 Session 13, SLIS-IU

6 CGI Examples Email Webpage Fetch File Upload Simple Search
HTML form CGI Webpage Fetch File Upload Simple Search Advanced Search S517 Session 10, SLIS-IU


Download ppt "CGI II: Cookies & Stuff Web Programming."

Similar presentations


Ads by Google