0% found this document useful (0 votes)
134 views22 pages

Final PW Lab PGM Vtu1

The document describes programs developed for a programming lab: 1. An XHTML document is developed that illustrates the use of an external style sheet, ordered list, table, borders, padding, color, and the <span> tag. 2. An XHTML file is developed that includes Javascript scripts to: a) Input a number and output the first n Fibonacci numbers; b) Input a number and output a table of numbers from 1 to n and their squares. 3. An XHTML file is developed that includes Javascript functions to: a) Take a string as a parameter and output the position of the leftmost vowel; b) Take a number as a parameter and output the number with its digits in reverse order

Uploaded by

Pavan Kotyal
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
134 views22 pages

Final PW Lab PGM Vtu1

The document describes programs developed for a programming lab: 1. An XHTML document is developed that illustrates the use of an external style sheet, ordered list, table, borders, padding, color, and the <span> tag. 2. An XHTML file is developed that includes Javascript scripts to: a) Input a number and output the first n Fibonacci numbers; b) Input a number and output a table of numbers from 1 to n and their squares. 3. An XHTML file is developed that includes Javascript functions to: a) Take a string as a parameter and output the position of the leftmost vowel; b) Take a number as a parameter and output the number with its digits in reverse order

Uploaded by

Pavan Kotyal
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 22

Pw lab pgms:

BY MANJU:--
1. Develop and demonstrate a XHTML document that illustrates the use external style
sheet, ordered list, table, borders, padding, color, and the <span> tag.

lab1.html
<?xml version = "1.0" encoding = "utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head><title>Ordered List</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<body bgcolor="orange">
<h1>Ordered List</h1>
<ol><li>Software Engineering</li>
<ol>
<li>Six essentials of SE</li>
<li>Emergent Properties of SE</li>
<li>Socio technical reasons of SE</li>
<ol>
<li>Security</li>
<li>Vulnerability</li>
</ol>
</ol>
</ol>
<h1>Table</h1>
<table border=1 >
<tr class="row1">
<th>Emp Number</th>
<th>Name</th>
<th>Designation</th>
<th>Date of Joining</th>
<th>Salary</th>
</tr>
<tr class="row2">
<td>E101</td>
<td>Rakesh</td>
<td>Software Engineer</td>
<td>24-4-1998</td>
<td>22000</td>
</tr>
<tr class="row2">
<td>E102</td>
<td>Rajesh</td>
<td>Senior Engineer</td>

1 http://firefriendsmanju.webs.com| :-
Pw lab pgms:

<td>24-4-1999</td>
<td>18000</td>
</tr>
<tr class="row2">
<td>E103</td>
<td>Prashanth</td>
<td>Software Engineer</td>
<td>24-4-2000</td>
<td>18000</td>
</tr>
</table>
<h1>Representing Border Style</h1>
<p class="borders1">Welcome to CGI programming</p>
<p class="borders3">Welcome to Scripting</p>
<p class="borders2">Welcome to CSS</p>
<h1>Representing Span tag</h1>
<p><span class="spanblue">dsfk</span>Welcome to HTML with CSS</p>
<p class="borders2">klsjdfklsj<span class="spanblue">dsfk</span>Welcome to Scripting</p>
</body>
</html>

Style.css
h1{text-decoration:underline}
ol{list-style-type:upper-roman;}
ol ol{list-style-type:upper-alpha;}
ol ol ol{list-style-type:decimal;}

ol.one{list-style-type:lower-roman;}
ol.one ol.one {list-style-type:lower-alpha;}
ol.one ol.one ol.one{list-style-type:decimal;}

table { border-top-width:low;
border-bottom-width:thick;
border-left-width:medium;
border-right-width:thin;

border-top-color:red;
border-bottom-color:gray;
border-left-color:blue;
border-right-color:purple;

border-top-style:dotted;
border-bottom-style:dashed;
border-left-style:double;
border-right-style:line;

2 http://firefriendsmanju.webs.com| :-
Pw lab pgms:

margin-left:0.5in;
margin-right:0.5in;
margin-top:0.5in;
margin-bottom:0.4in;

padding-left:7in;
padding-right:9in;
padding-top:12.5in;
padding-bottom:1.4in;

}
tr.row1{background:"red";}
tr.row2{color:"teal";}
p.borders1{border-style:dashed;}
p.borders2{border-style:dotted;}
p.borders3{border-style:double;}

.spanblue{font-size:24pt;
font-family:"gothic";
color:"blue";
font-weight:300;
}

OUTPUT:

3 http://firefriendsmanju.webs.com| :-
Pw lab pgms:

2. Develop and demonstrate a XHTML file that includes Javascript script for the following
problems:
a) Input: A number n obtained using prompt
Output: The first n Fibonacci numbers
<?xml version = "1.0" encoding = "utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<!-- lab2a.html -->

<html xmlns = "http://www.w3.org/1999/xhtml">


<body>

<script type="text/javascript">

var fib1=0,fib2=1,fib=0;
var num = prompt("Enter a number : \n", "");

if(num!=null && num>0)


{
document.write("<h1>" + num + " Fibonocci are <br></h1>");
if(num==1)
document.write("<h1> "+ fib1 + "</h1>");
else
document.write("<h1>" + fib1 + " " + fib2 + "</h1>");

for(i=3;i<=num; i++)
{
fib= fib1 + fib2;
document.write("<h1> " + fib + "</h1>");
fib1=fib2;
fib2=fib;
}
}
else
alert("No Proper Input");
</script>

</body>
</html>
Output:--

4 http://firefriendsmanju.webs.com| :-
Pw lab pgms:

2. b) Input: A number n obtained using prompt


Output: A table of numbers from 1 to n and their squares using
<?xml version = "1.0" encoding = "utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<!-- lab2b.html
A trivial document
-->

<html xmlns = "http://www.w3.org/1999/xhtml">


<body>
<script type="text/javascript">

var num = prompt("Enter a number : \n", "");

if(num >0 && num !=null){


msgstr="Number and its Squares are \n";
for(i=1;i <= num; i++)
{
msgstr = msgstr + i + " - " + i*i + "\n";
}
alert(msgstr)
}
else
alert("No input supplied");
</script>
</body>
</html>

Output:--

5 http://firefriendsmanju.webs.com| :-
Pw lab pgms:

3. Develop and demonstrate a XHTML file that includes Javascript script that uses
functions for the following problems:
a) Parameter: A string
Output: The position in the string of the left-most vowel

<?xml version = "1.0" encoding = "utf-8" ?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<!-- lab3a.html -->
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function disp(str)
{
sml=-1;
alert(str.value)
text = str.value

var ia = text.toLowerCase().indexOf("a");
var ie = text.toLowerCase().indexOf("e");
var ii = text.toLowerCase().indexOf("i");
var io = text.toLowerCase().indexOf("o");
var iu = text.toLowerCase().indexOf("u");

if(ia >= 0) sml=ia;


else if(ie >= 0) sml=ie;
else if(ii >= 0) sml=ii;
else if(io >= 0)sml=io;
else if(iu>=0) sml=iu;
if(sml != -1)
alert("The leftmost position of the vowel is " + sml);
else
alert("No vowel found");
}
</script>
</head>
<body>
Enter a String :
<input type=text name=strng>
<input type="button" value="Click me!" onclick="disp(strng)" >
</body>
</html>

6 http://firefriendsmanju.webs.com| :-
Pw lab pgms:

3. b) Parameter: A number
Output: The number with its digits in the reverse order

<?xml version="1.0" encoding="utf-8" ?>

<!DOCTYPE html PUBLIC "-//w3c//DTD XHTML 1.1//EN"

"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<script type="text/javascript">
function disp(num)
{
var rn=0, n= Number(num.value);
while(n!=0)
{
r = n%10;
n = Math.floor(n/10);
rn = rn*10 + r;
}
alert("The " + num.value + " in reverse is " + rn);

}
</script>
</head>
<body>
Enter a number :
<input type=text name=number>
<input type="button" value="Click me!" onclick="disp(number)" >
</body>
</html>

Output:--

7 http://firefriendsmanju.webs.com| :-
Pw lab pgms:

4. a) Develop and demonstrate, using Javascript script, a XHTML


document that collects the USN ( the valid format is: A digit from 1 to 4
followed by two upper-case characters followed by two digits followed by
two upper-case characters followed by three digits; no embedded spaces
allowed) of the user. Event handler must be included for the form element
that collects this information to validate the input. Messages in the alert
windows must be produced when errors are detected.
<html>
<head>
<script type="text/javascript">
function go()
{
document.f1.t1.focus();
}
function check()
{
var n=document.f1.t1.value;
alert(n);
reg= /^([1-4][A-Z][A-Z]\d{2}[A-Z][A-Z]\d{3})$/ ;
var k= reg.test(n) ;
if(k==false)
alert("Invalid USN = "+ n +" test = " + reg.test(n));
else
alert("valid USN = "+ n +" test = " + reg.test(n));
}
function check1()
{
n=document.f1.t1.value;
alert("n= "+n);
reg= /^([1-4][A-Z][A-Z]\d{2}[A-Z][A-Z]\d{3})$/ ;
var k= reg.test(n) ;
if(k==false)
alert("Invalid USN = "+ n +" test = " + reg.test(n));
else
alert("valid USN = "+ n +" test = " + reg.test(n));
}
</script>
</head>
<body >
<form name="f1" onsubmit="check1()">
Enter USN =
<input type="text" name="t1" value="" />
<input type="submit" />

</form>
</body>
</html>

8 http://firefriendsmanju.webs.com| :-
Pw lab pgms:

4b) Modify the above program to get the current semester also
(restricted to be a number from 1 to 8)
4b.html

<html>
<head>
<script language = "javascript">
function getsem()
{
var usn = document.f1.t1.value;
reg= /^([1-4][A-Z][A-Z]\d{2}[A-Z][A-Z]\d{3})$/ ;

var k= reg.test(usn) ;
if(k==false)
{
alert("Invalid USN = "+ usn +" test = " + reg.test(usn));
}
if (k==true)
{
alert("valid USN = "+ usn +" test = " + reg.test(usn));
var s = usn.substring(3,5);
var s1 = parseInt(s);
var today=new Date();
var thisyear = today.getFullYear();
var k=s;
var k1="20"+s;
var joinyear = parseInt(k1);
var y=thisyear-joinyear;
if(y>3)
{
y=3;
}
var m=today.getUTCMonth();
m=m+1;
if(m<7)
{
sem=(y*2);
}
else
{
sem=(y*2)+1
}
alert("Semester = " +sem);
}
}
</script>
</head>
<body>
<form name = "f1">
<input type = "text" name = "t1" value = "">
<input type = "button" value = "Click Me" onclick ="getsem()">
</form>
</body>
</html>

9 http://firefriendsmanju.webs.com| :-
Pw lab pgms:

5. a) Develop and demonstrate, using Javascript script, a XHTML


document that contains three short paragraphs of text, stacked on top of
each other, with only enough of each showing so that the mouse cursor
can be placed over some part of them. When the cursor is placed over the
exposed part of any paragraph, it should rise to the top to become
completely visible.

5a.html
<CTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Program 5</title>
<link rel="stylesheet" href="./style.css" media="screen" type="text/css" />
<script type="text/javascript">
var topLayer="layer3";
function mover(toTop)
{

var oldTop = document.getElementById (topLayer).style;


var newTop = document.getElementById (toTop).style;

oldTop.zIndex="0";
newTop.zIndex="10"
topLayer=document.getElementById(toTop).id;
}

</script>
</head>
<body>
<h1>
<div id="layer1" style="background: #f000f0; z-index: 10;position: absolute; left: 10px; top:
100px; width: 400px;" onmouseover="mover('layer1')">
a0) Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi dapibus.
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis
egestas.
Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;
Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.

</div>
<div id="layer2" style="background: #00f0f0; z-index: 2; position: absolute; left: 60px; top:
150px; width: 400px;" onmouseover="mover('layer2')">
a1) Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi dapibus.
Donec vitae pede a nisl ultricies viverra. Integer bibendum.

10 http://firefriendsmanju.webs.com| :-
Pw lab pgms:

Fusce ipsum quam, accumsan a, ornare at, consectetuer sit amet, diam.
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;
Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.

</div>
<div id="layer3" style="background: #f0f000; z-index: 0; position: absolute; left: 110px; top:
200px; width: 400px;" onmouseover="mover('layer3')">
a2) Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi dapibus.
Donec vitae pede a nisl ultricies viverra. Integer bibendum.
Fusce ipsum quam, accumsan a, ornare at, consectetuer sit amet, diam.
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;
Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.

</div>
</body>
</html>
Style.css

body {
font-family: 'Arial', sans-serif;
font-size: 14px;
}

h1 {
font-size: 18px;
font-style: italic;
}

a{
color: #7070f0;
text-decoration: none;
}

a:visited {
color: #7070f0;
text-decoration: none;
}

a:hover {
color: #9090f9;
text-decoration: underline;
}

11 http://firefriendsmanju.webs.com| :-
Pw lab pgms:

5b) Modify the above document so that when a paragraph is moved from
the top stacking position, it returns to its original position rather than to
the bottom

5b.html

<?xml version="1.0" encoding="UTF-8"?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Program 5</title>
<link rel="stylesheet" href="./style.css" media="screen" type="text/css" />
<script type="text/javascript">
function bringToTop(id, index, n) {
var div = document.getElementById ( id + index );
var i, maximum;
maximum = -1;
for(i=0; i<n; i++) {
if ( i != index && document.getElementById( id + i ).style.zIndex > maximum )
maximum = document.getElementById( id + i ).style.zIndex;
}
div.style.zIndex = maximum + 1;
}

function resetPosition(id, index) {


var div = document.getElementById ( id + index );
div.style.zIndex = index;
}
</script>
</head>
<body>

<h1>
b) Paragraphs that come to top on mouse hover and move back to original position on mouse
out
</h1>
<div id="b0" style="background: #f000f0; z-index: 0; position: absolute; left: 10px; top:
500px; width: 400px;" onmouseover="bringToTop('b',0,3);" onmouseout="resetPosition('b',0);">
b0) Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi dapibus.
Donec vitae pede a nisl ultricies viverra. Integer bibendum.
Fusce ipsum quam, accumsan a, ornare at, consectetuer sit amet, diam.
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
gravida vitae, cursus et, sem.

12 http://firefriendsmanju.webs.com| :-
Pw lab pgms:

</div>
<div id="b1" style="background: #00f0f0; z-index: 1; position: absolute; left: 60px; top:
550px; width: 400px;" onmouseover="bringToTop('b',1,3);" onmouseout="resetPosition('b',1);">
b1) Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi dapibus.
Donec vitae pede a nisl ultricies viverra. Integer bibendum.
Fusce ipsum quam, accumsan a, ornare at, consectetuer sit amet, diam.
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
aliquam, pede ut aliquam iaculis,
lectus quam cursus mauris, nec rhoncus metus eros vitae nibh.
</div>
<div id="b2" style="background: #f0f000; z-index: 2; position: absolute; left: 110px; top:
600px; width: 400px;" onmouseover="bringToTop('b',2,3);" onmouseout="resetPosition('b',2);">
b2) Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi dapibus.
Donec vitae pede a nisl ultricies viverra. Integer bibendum.
Fusce ipsum quam, accumsan a, ornare at, consectetuer sit amet, diam.
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
</div>
</body>
</html>
Style.css

body {
font-family: 'Arial', sans-serif;
font-size: 14px;
}

h1 {
font-size: 18px;
font-style: italic;
}

a{
color: #7070f0;
text-decoration: none;
}

a:visited {
color: #7070f0;
text-decoration: none;
}

a:hover {
color: #9090f9;
text-decoration: underline;
}

13 http://firefriendsmanju.webs.com| :-
Pw lab pgms:

6. a) Design an XML document to store information about a student in an engineering


college affiliated to VTU. The information must include USN, Name, Name of the College,
Brach, Year of Joining, and e-mail id. Make up sample data for 3 students. Create a CSS
style sheet and use it to display the document.
lab6a.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/css" href="lab6a.css"?>
<!DOCTYPE student [
<!ELEMENT student (title,student1,student2,student3)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT students (usn+,name+,college+,branch+,joiningyear+,emailid+)>
<!ELEMENT usn (regno)>
<!ELEMENT name (name1)>
<!ELEMENT college (cname)>
<!ELEMENT branch (course)>
<!ELEMENT joiningyear (jy)>
<!ELEMENT emailid (email)>
<!ELEMENT regno (#PCDATA)>
<!ELEMENT name1 (#PCDATA)>
<!ELEMENT cname (#PCDATA)>
<!ELEMENT course (#PCDATA)>
<!ELEMENT jy (#PCDATA)>
<!ELEMENT email (#PCDATA)>
]>
<student>
<title>STUDENT DETAILS</title>
<students>
<usn><regno> Register Number :</regno> 1SSO6CS001 </usn>
<name><name1> NAME :</name1> AAAAAAAA </name>
<college><cname> College :</cname> SSIT </college>
<branch><course> COURSE :</course> CSE </branch>
<joiningyear><jy> Year of Joining :</jy> 2006 </joiningyear>
<emailid><email> Email :</email> [email protected]</emailid>
</students>
<students>
<usn><regno> Register Number :</regno> 1SSO6CS002 </usn>
<name><name1> NAME :</name1> BBBBBBBB </name>
<college><cname> College :</cname> SSIT </college>
<branch><course> COURSE :</course> CSE </branch>
<joiningyear><jy> Year of Joining :</jy> 2006 </joiningyear>
<emailid><email> Email :</email> [email protected]</emailid>
</students>
<students>
<usn><regno> Register Number :</regno> 1SSO6CS003 </usn>
<name><name1> NAME :</name1> CCCCCCCC </name>
<college><cname> College :</cname> SSIT </college>

14 http://firefriendsmanju.webs.com| :-
Pw lab pgms:

<branch><course> COURSE :</course> CSE </branch>


<joiningyear><jy> Year of Joining :</jy> 2006 </joiningyear>
<emailid><email> Email :</email> [email protected]</emailid>
</students>

<students>
<usn><regno> Register Number :</regno> 1SSO6CS004 </usn>
<name><name1> NAME :</name1> CJCJCJCJCJ </name>
<college><cname> College :</cname> SSIT </college>
<branch><course> COURSE :</course> CS </branch>
<joiningyear><jy> Year of Joining :</jy> 2005 </joiningyear>
<emailid><email> Email :</email> [email protected]</emailid>
</students>
</student>
lab6a.css
student
{
background-color: cyan;
width: 100%;
}
title{
font-weight:bold;
font-color:maroon;
font-size:65pt;
text-decoration:underline;
margin-left:250pt;
}
students
{
display: block;
margin-bottom: 30pt;
margin-left: 10pt;
background-color:pink;
}
usn,name,college,branch,joiningyear,emailid
{
font-size:20pt;
display: block;
color: #000000;
margin-left: 20pt;
}
regno,name1,cname,course,jy,email{
font-size:30pt;
font-weight:bold;
font-color:blue;
}

15 http://firefriendsmanju.webs.com| :-
Pw lab pgms:

6b) Create an XSLT style sheet for one student element of the above
document and use it to create a display of that element.
6b.xml
<?xml version = "1.0"?>
<!-- 6b.xml -->
<?xml:stylesheet type = "text/xsl" href = "6b.xsl" ?>
<VTU>
<USN> 1RN08ISE </USN>
<name> Amar </name>
<college> RNSIT </college>
<branch> ISE </branch>
<YOJ> 2007 </YOJ>
<email> [email protected] </email>
</VTU>
6b.xsl
<?xml version = "1.0"?>
<!-- 6b.xsl An XSLT Stylesheet for 5b.xml using templates -->
<xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"
xmlns = "http://www.w3.org/1999/xhtml">

<xsl:template match = "VTU">


<html><head><title> Style sheet for 5b.xml </title>
</head><body>
<h2> VTU Student Description </h2>
<span style = "font-style: italic; color: blue;"> USN:
</span>
<xsl:value-of select = "USN" /> <br />
<span style = "font-style: italic; color: blue;"> Name:
</span>
<xsl:value-of select = "name" /> <br />
<span style = "font-style: italic; color: blue;"> College:
</span>
<xsl:value-of select = "college" /> <br />
<span style = "font-style: italic; color: blue;"> Branch:
</span>
<xsl:value-of select = "branch" /> <br />
<span style = "font-style: italic; color: blue;"> Year of Join:
</span>
<xsl:value-of select = "YOJ" /> <br />
<span style = "font-style: italic; color: blue;"> E-Mail:
</span>
<xsl:value-of select = "email" /> <br />
</body></html>
</xsl:template>
</xsl:stylesheet>

16 http://firefriendsmanju.webs.com| :-
Pw lab pgms:

7. a) Write a Perl program to display various Server Information like


Server Name, Server Software, Server protocol, CGI Revision etc.

Program7a.html

<html>
<head><title>Server Info</title></head>
<body bgcolor=orange><br>
<form action="http://localhost/cgi-bin/program7a.pl" method="get">
<center><input type="submit" value="Show Server Information"></center>
</form>
</body>
</html>

program7a.pl

#!/usr/bin/perl
print<<1a;
Content-type:text/html\n\n
<html>
<head><title>Environment Variables</title></head>
<body bgcolor=orange>
<table cellpadding=5 border=1>
<tr>
<th>ENV-VARIABLE</th>
<th>VALUE</th>
</tr>
1a
foreach $i(sort keys %ENV) {
print "<tr><td>$i<td>$ENV{$i}</tr>";
}
print "</table></body></html>";

17 http://firefriendsmanju.webs.com| :-
Pw lab pgms:

7b) Write a Perl program to accept UNIX command from a HTML form
and to display the output of the command executed.

Program7b.html

<html>
<head><title>Unix Command</title></head>
<body bgcolor=orange>
<form method=GET action="http://localhost/cgi-bin/program7b.pl" name=form1>
<center><br><H1>ENTER UNIX COMMAND TO BE EXECUTED</H1>
<input type=text name=msg><p>
<input type=submit value="CLICKME">
</form>
</body>
</html>
program7b.pl

#!/usr/bin/perl
use CGI;
$q=new CGI;
$cmd=$q->param("msg");
print<<1b;
Content-type:text/html\n\n
<html>
<head><title>Unix Command</title></head>
<body bgcolor=orange>
<h1><pre><center>
The output of UNIX command is <br>
1b
system($cmd);
print "</center></h1></body></html>";

--------------------------------------------------------------------------------------------------------------------

9. Write a Perl program to display a digital clock which displays the


current time of the server
9.pl
#!/usr/bin/perl
$delay = 1;
($seconds,$minutes,$hour) = localtime (time);
print "Refresh: ", $delay, "\n";
print "Content-type: text/plain", "\n\n";
print "Digital clock:\t";
print "$hour:$minutes:$seconds";
exit(0);
---------------------------------------------------------------------------------------------------------

18 http://firefriendsmanju.webs.com| :-
Pw lab pgms:

8. a) Write a Perl program to accept the User Name and display a


greeting message randomly chosen from a list of 4 greeting messages.

8a.html

<html>
<head><title> name </title></head>
<body bgcolor="aabbcc">
<h3> enter name & receive the greetings </h3>
<form action="/cgi-bin/8a.pl" method="get">
name:<input type="text" name="name"><br/><br/>
<input type="submit" value="submit">
<input type="reset" value="reset">
</form>
</body>
</html>

8a.pl

#!/usr/bin/perl
use strict;
use CGI':standard';
my $name=param("name");
print header();
print start_html(-title=>'Greeting message'-bgcolor=>'1E90FF');
print h2("Hello $name");
my $r=int(rand(4));
print "random-".$r;
if($r==0) {
print h2("Hai".$name);
}
if($r==1) {
print h2("great Day".$name);
}
print "<br>";
if($r==2) {
print h2("Welcome".$name);
}
print "<br>";
if($r==3) {
print h2("Good day".$name);
}
print end_html();

19 http://firefriendsmanju.webs.com| :-
Pw lab pgms:

8. b) Write a Perl program to keep track of the number of visitors visiting the web page
and to display this count of visitors, with proper headings.

8b.pl
#! /usr/bin/perl
use CGI’:standard’;
use strict;
use DBI;
my $c;
my $dbh=DBI->connect(‘DBI:mysql’,’root’,’iamgod’);
my $sth=$dbh->prepare(‘select * from visitors’);
$sth->execute();
$c=$sth->fetchrow();
print header(),
start_html(),
h1(“count=$c”),
end_html();
$c=$c+1;
$sth=$dbh->prepare(‘update visitors set count=?’);
$sth->execute($c);
$sth->finish();
$dbh->disconnect();
exit(0);

//check single quotes and double quotes correctly in above pgm//pgm is fine!!

11. Write a PHP program to store current date-time in a COOKIE and


display the ‘Last visited on’ date-time on the web page upon reopening of
the same page

11.php

<?php
$value=`date +%D%T`;
$xyz= 60 * 60 *24 *60 + time();
setcookie("TestCookie",$value, $xyz);
echo "Cookie has been set";
echo "The Last visited Time and Date";
echo $_COOKIE["TestCookie"];
?>

20 http://firefriendsmanju.webs.com| :-
Pw lab pgms:

12. Write a PHP program to store page views count in SESSION, to


increment the count on each refresh, and to show the count on web page.

12.php

<?php
session_start();
session_register("count");

if (!isset($_SESSION))
{
$_SESSION["count"] = 0;
echo "<p>Counter initialized</p>\n";
}
else { $_SESSION["count"]++; }

echo "<p>The counter is now <b>$_SESSION[count]</b></p>".


"<p>reload this page to increment</p>";
?>

10. Write a Perl program to insert name and age information entered by the
user into a table created using MySQL and to display the current contents of
this table.

<html>
<body>
<form action="http://localhost/cgi-bin/10.pl">
Name : <input type="text" name="name"> <br>
Age :<input type="text" name="age"> <br>
<input type="submit" value="Submit">
</form>
</body>
</html>

10.pl

#! /usr/bin/perl
print "Content-type: text/html\n\n";
print "<HTML><TITLE>Result of the insert operation </TITLE>";
use CGI ':standard';
use DBI;
$dbh=DBI->connect("DBI:mysql:test","root","");
$name=param("name");
$age=param("age");

21 http://firefriendsmanju.webs.com| :-
Pw lab pgms:

$qh=$dbh->prepare("insert into stud values('$name','$age')");


$qh->execute();
$qh=$dbh->prepare("select * from stud");
$qh->execute();
print "<table border size=1><tr><th>Name</th><th>Age</th></tr>";

while ( ($name,$age)=$qh->fetchrow())
{
print "<tr><td>$name</td><td>$age</td></tr>";
}

print "</table>";
$qh->finish();
$dbh->disconnect();
print"</HTML>";

22 http://firefriendsmanju.webs.com| :-

You might also like