Download presentation
Presentation is loading. Please wait.
Published byMichael Price Modified over 6 years ago
1
CSE 102 Introduction to Web Design and Programming
Perl & CGI
2
What is Perl? The Practical Extraction & Report Language
Open Source (1987) freely available for downloading from the Comprehensive Perl Archive Network it is already installed on Sparky The Perl scripting language has many uses, for us: Web CGI programming (like we’ve been doing)
3
What can you do with Perl
Lots: scalar variables arrays mathmatical arithmetic string operations boolean arithmetic conditional statements standard I/O file I/O interprocess I/O iteration functions
4
Script File Issues When transfering files from Windows to Unix, some encoding issues So, we can use Pico in Unix, to use: Open SSH Terminal Window and login cd www cd cgi-bin ls pico filename Once pico opens, you may begin typing Commands: CTRL-O to save (look at bottom of screen) CTRL-X to exit Also, make sure all files have 755 file permissions
5
CookieMonster.html <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" " <html xmlns=" xml:lang="en" lang="en"> <head> <title>Domain Name Availability Check</title> </head> <body> <h2>A Cookie Demo</h2> <h3>The Cookie Monster wants to know</h3> <form method="post" action=" enctype="application/x-www-form-urlencoded"> <p>What sort of cookies do you like? <input name="cookie_type" size="16" type="text" /> <input type="submit" value="Submit" /> </p> </form> </body> </html>
6
cookiemonster.pl #!/usr/local/bin/perl -T use CGI qw(:standard);
$ENV{'PATH'}='/usr/sbin:/sbin:/bin:/usr/bin'; CDPATH ENV BASH_ENV)}; ## script values REPLACE aesmaili with YOUR USERNAME $cookie_path = '/cgi-bin/cgiwrap/aesmaili/cookiemonster.pl'; $whois="/usr/bin/whois"; ##### in-script configuration values END $cookie_type=param('cookie_type'); ## set cookie $the_cookie = cookie(-name=>'TheCookieMonsterCookie!!!', -value=>$cookie_type, -expires=>' h', -path=>$cookie_path); # Print the cookie header with expiration date print header(-cookie=>$the_cookie, -charset=>'UTF-8'); ##### send HTML page outputFile(); ################# subroutines ##################### sub outputFile { print <<END; <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" " <html xmlns=" xml:lang="en" lang="en"> <head><title>Cookie Response</title></head> <body style="background-color:blue; color:white"> <h3>The Cookie Monster knows you like $cookie_type cookies</h3> <p>I put a cookie on your computer</p> </body> </html> END } cookiemonster.pl
7
FileUploader.html <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" " <html xmlns=" xml:lang="en" lang="en"> <head> <title>File Uploader</title> </head> <body> <p style="font-weight: bold; font-size: larger"> Upload a picture</p> <form method="post" action=" enctype="mulipart/form-data"> <input type="file" name="yourpic" /><br /> <input type="submit" value="Submit" /> </form> </body> </html>
8
fileuploader.pl #!/usr/bin/perl
use CGI qw(:standard); ## cgi perl module $query = new CGI; var $name = param('yourpic'); $fh = $query->upload($name); binmode(fh); binmode(OUT); while ( <$fh> ) { print OUT; } close OUT; print "Content-type: text/html\r\n\r\n"; print <<END; <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" " <html xmlns=" xml:lang="en" lang="en"> <head><title>File Uploading</title></head> <body> <h3>File Uploaded: $name</h3> <p><img src="$name" /></p> </body> </html> END fileuploader.pl
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.