:::::::::::::: lp1a.pl :::::::::::::: #!/usr/bin/perl -w #lp1a.pl use CGI ':standard'; use CGI '*table'; print header, start_html('Server Information'), start_table({-border=>1}), caption("Server Information"); %info=("Server Name"=>server_name, "Server Software"=>server_software, "Server protocol"=>server_protocol, "CGI Revision"=>$ENV{GATEWAY_INTERFACE}, "Server Port"=>server_port, "Document root"=>$ENV{DOCUMENT_ROOT}); foreach(keys %info){ print Tr( td($_), td($info{$_}) ), "\n"; } print end_table(),end_html(),"\n"; :::::::::::::: lp1b.html :::::::::::::: Input command

Enter UNIX command

:::::::::::::: lp1b.pl :::::::::::::: #!/usr/bin/perl -w #lp1b.pl use CGI ':standard'; print header, start_html("Output"), p(u('Output on executing "', b(param "command")),'":'), "
";
system(param 'command');
print "
",end_html; :::::::::::::: lp2a.html :::::::::::::: Input name

Enter your name

:::::::::::::: lp2a.pl :::::::::::::: #!/usr/bin/perl -w #lp2a.pl use CGI ':standard'; print header, start_html(-title=>"Greeting Message"), p("Hello, ",b(param("uName")),"... Welcome to CGI Programming Lab!"), end_html; :::::::::::::: lp2b.html :::::::::::::: Click to visit Hit count

:::::::::::::: lp2b.pl :::::::::::::: #!/usr/bin/perl -w use CGI ':standard'; print header() ,start_html("Hit count"); open RD,"; close RD; open(WR,">/var/www/cgi-bin/lp2b.txt")or print"$!"; print WR ++$c; close WR; print p("This is visit no. ",b($c)," to this page.") ,end_html; :::::::::::::: lp3.pl :::::::::::::: #!/usr/bin/perl -w use CGI ':standard'; print header, start_html("Greeting"); ($s,$m,$h)=localtime(time); if($h>22 or $h<4){ $p="Good Night"; } elsif($h<12){ $p="Good Morning"; } elsif($h<16){ $p="Good Afternoon"; } else{ $p="Good Evening"; } $webmaster="root"; open WM, "/usr/bin/w -hs $webmaster |"; if(=~ /$webmaster/){ $l=""; } else{ $l=" not"; } print p(b("$p"),"..."), p("Webmaster is currenly$l logged in."), end_html; close WM; :::::::::::::: lp4.html :::::::::::::: Click to view clock

Click here to view digital clock.

:::::::::::::: lp4.pl :::::::::::::: #!/usr/bin/perl -w use CGI ':standard'; print header, start_html(-head=>meta({-http_equiv=>"Refresh", -content=>"1"}), -title=>"Current Server Time"), p("The time now is ",b($t=localtime(time)),"."); end_html; :::::::::::::: lp5.pl :::::::::::::: #!/usr/bin/perl -w use DBI; use CGI ':standard'; use CGI '*table'; $db=DBI->connect('DBI:mysql:lab','kbsbng','kbsbng')or die(DBI::errstr); $q=$db->prepare("Select * From NameAndAge")or die(DBI::errstr); $q->execute()or die(DBI::errstr); print header, start_html("Contents of NameAndAge"), start_table({-border=>1,-width=>"100%"}), th("Name"), th("Age"); while(@row=$q->fetchrow){ print Tr( td($row[0]), td($row[1]) ), "\n"; }; $q->finish; $db->disconnect; print end_table,end_html,"\n"; :::::::::::::: lp6.html :::::::::::::: Input data
Name
Age
:::::::::::::: lp6.pl :::::::::::::: #!/usr/bin/perl -w #lp6.pl use CGI ':standard'; use CGI '*table'; use DBI; print header ,start_html("Record insertion"); $db= DBI->connect("DBI:mysql:lab",'kbsbng','kbsbng')or print("Could not connect: ".DBI::errstr); $q=$db->prepare("INSERT INTO NameAndAge VALUES (?,?)"); $q->execute(param("name"),param("age"))or print("Could not execute query: ".$db->errstr); $q->finish; $q=$db->prepare("SELECT * FROM NameAndAge"); $q->execute()or die("Could not execute query: ".$db->errstr); print p(b("Insertion successful.")) ,p("The present contents of the table are: ") ,start_table({-border=>1,-align=>"center"}) ,caption(b("Table NameAndAge")), ,th("Name"),th("Age"); while(@row=$q->fetchrow){ print Tr( td($row[0]), td({-align=>"center"},$row[1]) )."\n"; } print end_table,end_html; $q->finish; $db->disconnect;