CGI Programming in Perl

Cgi programming in perl l.jpg
1 / 26
0
0
1065 days ago, 405 views
PowerPoint PPT Presentation

Presentation Transcript

Slide 1

´╗┐Programming Tools CGI Programming in Perl

Slide 2

CGI Programming Last time we took a gander at outlining a static page. Today we will perceive how to outline dynamic pages utilizing CGI programs. A CGI program permits the client to interface with a site page by creating HTML code that relies on upon the client input. For instance, website pages with a section frame or catches utilize a CGI program to get the contribution from the client, and show fitting results. Since the Web principally contains content, Perl is the most prevalent dialect for CGI programming since it is great at content control.

Slide 3

CGI Programming cssystem considers CGI programs a security hazard, and does not permit them. ITSC , be that as it may, permits CGI programs e.g., uststu1.ust.hk, uststu2.ust.hk Place your CGI programs in a registry called cgi-canister in your public_html index. mkdir $HOME/public_html/cgi-canister Then, put your CGI programs under the index $HOME/public_html/cgi-receptacle and the URL is : http://home-cgi.ust.hk/cgi-container/cgiwrap/~login/program.cgi Your CGI program ought to likewise have execute consent set: chmod a+x program.cgi

Slide 4

My ITSC Home Page

Slide 5

HTML of My Home Page <HTML> <HEAD><TITLE>Andrew Horner</TITLE></HEAD> <BODY TEXT="aqua" LINK="violet" VLINK="deepviolet" ALINK="green" BGCOLOR="black"> <P ALIGN=CENTER><B><font size="8" face="Arial"> Andrew Horner</font></B></P> <P ALIGN=CENTER><B><font size="6" face="Arial"> <a href="http://www.cs.ust.hk/~horner">My "official" home page</a></font></B></P> <P ALIGN=CENTER><B><font size="6" face="Arial"> <a href=" http://home-cgi.ust.hk/cgi-container/cgiwrap/~horner/hello.cgi "> run CGI program</a> </font></B></P> </BODY> </HTML>

Slide 6

Hello World CGI Program Here is a "Welcome World" CGI program: #!/usr/neighborhood/canister/perl5 - w # hi world CGI program print <<END_OF_MULTILINE_TEXT; Content-sort: content/html <HTML> <HEAD> <TITLE>Hello World Program</TITLE> </HEAD> <BODY> <H1>Hello World!</H1> </BODY> </HTML> END_OF_MULTILINE_TEXT Blank line (no spaces or tabs) required!

Slide 7

Hello World Output

Slide 8

Here Documents The past case utilizes a here archive . It begins with the << and a word called the end token ( END_OF_MULTILINE_TEXT ). Here reports are a helpful approach to cite a multiline string. The string starts on the following line and proceeds up to a line containing the end token toward the begin of the line. Here archives are extremely valuable for creating HTML.

Slide 9

Hello World Details The Content-sort line recognizes the kind of yield we are producing ( content/html ). It is instantly trailed by a clear line, which must contain no spaces or tabs. This line isolates the CGI header from the HTML code. After the clear line comes the HTML, which is sent to be arranged and showed on the client's program.

Slide 10

Testing CGI Programs Make beyond any doubt your program runs legitimately from the summon line before testing it on the web: $ ~horner/public_html/cgi-container/hello.cgi Content-sort: content/html <HTML> <HEAD> <TITLE>Hello World Program</TITLE> </HEAD> <BODY> <H1>Hello World!</H1> </BODY> </HTML> $

Slide 11

The CGI Module Using here reports in Perl is still a difficult approach to create HTML. Perl has a CGI module to make it simpler. To utilize the CGI module in your program, incorporate the accompanying line close to the highest point of your program: use CGI qw(:standard); The utilization articulation resemble #include in C++; it acquires predefined capacities from another record at accumulate time.

Slide 12

Simpler Hello World Below is the "Welcome World" program utilizing the CGI module: #!/usr/neighborhood/receptacle/perl5 - w # hi world CGI program utilizing CGI module use CGI qw(:standard); print header(); print start_html("Hello World Program"); print h1("Hello World!"); print end_html(); CGI module capacities return strings, which we can then send to print .

Slide 13

Simpler Hello World In the past program, header() gives back a string containing the Content-sort line with a taking after clear line start_html( string ) returns string as a HTML title h1( string ) returns string as a first-level HTML heading, and p( string ) would return string as another HTML passage.

Slide 14

Adding Textfields CGI gives different gadgets to tolerating client contribution to shapes. A standout amongst the most widely recognized gadgets is the textfield gadget , which permits the client to enter message in a crate. Notwithstanding start_html() , you additionally require start_form() before you include your textfield. textfield() is frequently called inside a p() work. The main contention is the name of the textfield The second contention is the default esteem. print start_form; print p("Bill is: ", textfield("bill","cheap")); print end_form;

Slide 15

Hello Gates A frame with a textfield gadget: #!/usr/nearby/canister/perl5 - w # Bill Gates CGI program use CGI qw(:standard); $billvalue = param("bill"); # get esteem from bill-field print header(), start_html("Hello Bill Gates"); print h1("Hello Gates Lovers!"); if($billvalue){ # show, if client has hit Return print p("Yes, Bill is $billvalue."); }else{ # something else, request client input print hr, start_form; # hr() is <HR> HTML print p("Bill is: ", textfield("bill","cheap")); print end_form, hr; } print end_html();

Slide 16

Hello Gates Initial Screen When we tap on a connection that focuses to this program, you will see the underneath screen. The content field is at first loaded with the default esteem.

Slide 17

Hello Gates Result Screen If the client does not change the default esteem, but rather hits give back, the accompanying is shown:

Slide 18

Hello Gates Screens If the client changes the bill field as in the left screen, the right screen comes about:

Slide 19

Other Form Widgets Now we know how to make basic content fields and react to them. Shouldn't something be said about different gadgets like catches, checkboxes, and menus? The program on the accompanying slides incorporates: popup menus, a submit catch (named "send"), and a catch to reset the whole shape, eradicating all client input.

Slide 20

Bill's Fans page1 #!/usr/nearby/container/perl5 - w # Bill Gates CGI program v. 2 utilize strict; utilize CGI qw(:standard); print header(), start_html("Bill Gates Fans"); print h1("Bill Gates Fan Page"); if(param()){ # if the frame has as of now been rounded out my $who = param("name"); my $what = param("billWord"); my $howmuch = param("money"); if($howmuch == 100){ print p("Yes $who, Bill is $what, and he has 100,000,000 times more cash than you!"); }else{ print p("Incorrect $who! Charge has US\$100 billion."); }

Slide 21

Bill's Fans page2 }else{ # first time, so show clean shape print hr(), start_form(); print p("Your name: ", textfield("name")); print p("What is Bill? ", popup_menu("billWord", ["cheap", "rich", "powerful"])); print p("How numerous billion US dollars does Bill have? ", popup_menu("money", [1,10,100,1000])); print p(submit("send"), reset("clear")); print end_form; } print end_html();

Slide 22

References Why the square sections around the exhibits in the past illustration? ["cheap", "rich", "powerful"] [1,10,100,1000] The sections make a reference (pointer) to an exhibit. popup_menu() expects a cluster reference as its second contention. You can likewise make an exhibit reference by utilizing an oblique punctuation line as a part of front of a named cluster, as in \@choices : my @choices = qw(cheap, rich, capable); print p("What is Bill? ", popup_menu("billWord", \@choices));

Slide 23

Bill's Fans Initial Screen Here is the underlying screen and default values the client sees:

Slide 24

Bill's Fans Initial Screen The client fills in the shape:

Slide 25

Bill's Fans Result Screen The subsequent screen after the hitting "send":

Slide 26

Bill's Fans Result Screen The subsequent screen after the re-presenting the right esteem:

SPONSORS