You are on page 1of 18

Web Technology-II (CS-368)Practical Assignment

Name- khaire shraddha sambhaji


TYBsc(CS) - B

# ASSIGNMENT 1. ( Cookies and Session ) #

SET A

QUESTION - 1

//Session (vim track.php)

<html>
<head>
<title> Number of times the web page has been access using
Session</title>
</head>
<body>
<?php
session_start();
if(isset($_SESSION['count']))
$_SESSION['count']=$_SESSION['count']+1;
else
$_SESSION['count']=1;
echo "<h3>This page is accessed</h3>".$_SESSION['count'];
?>
</body>
</html>

//Cookie

<html>
<head>
<title> Number of times the web page has been access using
cookie</title>
</head>
<body>
<?php

if(isset($_COOKIE['count']))
{
$a=$_COOKIE['count'];
$a=$a+1;
setcookie('count',$a);
}

else
{
setcookie('count',2);
echo "<h3> This page is accessed 1st time </h3>";
}
echo"you accessed this page $a times";

?>
</body>
</html>

QUESTION - 2

//Html (preference.html)

<html>
<body>
<form action="preference.php" method="get">
<center>
<b>Select font Style:</b>
<input type=text name=s1>
<b>Enter font size:</b>
<input type=text name=s>
<b>Enter font color:</b>
<input type=text name=c>
<b>Enter background color:</b>
<input type=text name=b>
<input type=submit value="Next">
</center>
</form>
</body>
</html>

//php (preference.php)

<?php
echo "style is :".$_GET['s1']."
color is : ".$_GET['c']."
Background color is :".$_GET['b']."
size is ".$_GET['s'];
setcookie("set1",$_GET['s1'],time()+3600);
setcookie("set2",$_GET['c'],time()+3600);
setcookie("set3",$_GET['b'],time()+3600);
setcookie("set4",$_GET['s'],time()+3600);

?>
<a href="web.php">Show</a>

<?php

$style=$_COOKIE['set1'];
$color=$_COOKIE['set2'];
$size=$_COOKIE['set4'];
$bgcolor=$_COOKIE['set3'];
$msg="Software Deveolper ";
echo "<body bgcolor=$bgcolor>";
echo "<font color=$color size=$size face=$style>$msg";
echo "</font></body>";
?>

// SET B

// QUESTION - 1

//html (vim xyz.html)

<html>
<head>
<script>
function getans()
{
st1=document.getElementById('txtname').value;
st2=document.getElementById('txtpass').value;
ob=new XMLHttpRequest();
ob.on readystatechange=function()
{
if(ob.readystate==4 && ob.status==200)
{
if(ob.response Text==3)
{
alert("Sorry you lost the chances to login");
location="error.htm)";
}
else if(ob.responseText=="correct")
{
alert("you entered correct details");
}
else alert(ob.responseText);
}
}
ob.open("GET","xyz.php?n="+st1+" &p="+st2);
ob.send();
}
</script>
</head>
<body>

<input type=text id=txtname placeholder "username"></br>


<input type=password id=txtpass placeholder="password"></br>
<input type="button" onclick="getans()" value="login">
</body>
</html>

<html>
<body>
<h1> You lossed the chances of login </h1>
</body>
</html>

//php (vim xyz.php)

<?php
Session_start();
$nm=$_GET['n'];
$ps=$_GET['P'];
if($nm==$ps)
{
echo "Correct";
echo "Welcome";
}
else if(isset($_SESSION['cnt'])
{
$x=$_SESSION['cnt'];
$x=$x+1;
$_SESSION['cnt']=$x;
echo($-SESSION['cnt'];
if($_SESSION['cnt']>=3)
$_SESSION['cnt']=1;
}
else
{
$_SESSION['cnt']=1;
echo "1";
}
?>

// QUESTION - 2

//html (vim employee.html)

<html>
<body>
<form action="employee1.php method="get">
<center>
<h2>Enter Employee Details: </h2><br>
<table>
<tr><td><b> Emp no: </b></td>
<td> <input type=text name=eno> </td></tr>
<tr><td> Name: </b></td>
</td> <input type=text name=ename>
</td></tr>
<tr><td><b>Address:</b></td>
</td> <input type=text name=eadd>
</td></tr)
</table>
<br><input type=submit value=Show name=submit>
</center>
</form>
</body>
</html>

//php (vim employee1.php)

<?php
session_start();
$eno = $_GET['eno'];
$enm = $_GET['enm'];
$eadd = $_GET['eadd'];

$_SESSION['eno'] = $eno;
$_SESSION['enm'] = $enm;
$_SESSION['eadd'] = $eadd;
?>

<html>
<body>

<form action="employee2.php" method="post">


<center>
<h2>Enter Earnings of Employee:</h2>

<table>
<tr><td>Basic : </td><td><input type="text" name="e1"></td><tr>
<tr><td>DA : </td><td><input type="text" name="e2"></td></tr>
<tr><td>HRA : </td><td><input type="text" name="e3"></td></tr>
<tr><td></td><td><input type="submit" value=Next></td></tr>
</table>
</center>
</form>
</body>
</html>

//php (vim employee2.php)

<?php
session_start();
$e1 = $_POST['e1'];
$e2 = $_POST['e2'];
$e3= $_POST['e3'];

echo "<h3>Employee Details</h3> ";


echo "Name : ".$_SESSION['eno']."<br>";
echo "Address : ".$_SESSION['enm']."<br>";
echo "Class : ".$_SESSION['eadd']."<br><br>";

echo "basic : ".$e1."<br>";


echo "DA : ".$e2."<br>";
echo "HRA : ".$e3."<br>";

$total = $e1+$e2+$e3;
echo "<h2>Total Of Earnings Is : ".$total."</h2>";
?>
# ASSIGNMENT 2 ( XML and DOM ) #

// * SET A

// QUESTION - 1

//xml ( vim item1.xml )

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


<Stocklist>
<item type="fruit">
<name>apple</name>
<price>50</price>
<quantity>400</quantity>
</item>
<item type="vegetable">
<name>beetroot</name>
<price>60</price>
<quantity>500</quantity>
</item>
<item type="flowers">
<name>rose</name>
<price>20</price>
<quantity>100</quantity>
</item>
<item type="books">
<name>java</name>
<price>90</price>
<quantity>200</quantity>
</item>
<item type="notebook">
<name>classy</name>
<price>70</price>
<quantity>600</quantity>
</item>
</Stocklist>

//php ( vim displayitem.php )

<?php
$xml=simplexml_load_file('item1.xml');
foreach($xml->children() as $b)
{
echo "<br>ItemList<br>";
echo"<br>ItemName : ".$b->Itemname;
echo "<br>ItemPrice : ".$b->Itemprice;
echo"<br>ItemQuantity : ".$b->quantity;
echo"<br>";
}
?>

// QUESTION - 2

//css ( vim Item.css )

<?xml-stylesheet type="text/css"href="Item.css"?>
Item.css
Itemname
{
color:black;
font-family:copperplate Gothoic Light;
font-size:16pt;
font:bold;
}

Itemprice
{
color:yellow;
font-family:Arial;
font-size:12pt;
font:bold;
}
quantity
{
color:yellow;
font-family:Arial;
font-size:16pt;
font:bold;
}

//xml ( vim Item.xml )

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


<?xml-stylesheet type="text/css"href="Item.css"?
<ItemStock>
<item type="fruit">
<ItemName>Apple</ItemName>
<price>100</price>
<quantity>50</quantity>
</item>
<item type="flower">
<ItemName>Rose</ItemName>
<price>200</price>
<quantity>60</quantity>
</item>
<item type="vegetable">
<ItemName>Potato</ItemName>
<price>300</price>
<quantity>800</quantity>
</item>
</ItemStock>

// QUESTION - 3

//xml ( vim book.xml )

<?php
<?xml version="1.0" encoding="UTF-8"?>
<BookInfo>
<book>
<bookno>1</bookno>
<bookname>Java</bookname>
<authorname>Balguru Swami</authorname>
<price>250</price>
<year>2006</year>
</book>
<book>
<bookno>2</bookno>
<bookname>c</bookname>
<authorname>Dennis ritchie</authorname>
<price>500</price>
<year>1971</year>
</book>
</BookInfo>

//php ( vim book.php )

<?php
$xml=simplexml_load_file('book.xml');
foreach($xml->children() as $b)
{
echo "<br>BookList<br>";
echo"<br> Bookno :".$b->bookno;
echo"<br>BookName : ".$b->bookname;
echo"<br>AuthorName : ".$b->authorname;
echo "<br>Price : ".$b->price;
echo"<br>Year : ".$b->year;
echo"<br>";
}
?>

// SET B

// QUESTION - 1
//xml ( vim book1.xml )

<?xm] Version:"1.0" encoding="UTF-8"?>


<BookInfo>
<book>
<book no> 1 </book no>
<booknome> Java </book name>
<authorname> Swami </authorname>
<price> 250 </price>
<year> 2006 </year>
</book
<book>
<book no> 2 </book no>
<book name> C </bookname>
<authorname> Denis Ritche </authorname>
<price> 500 </price>
<year> 1971 </year)
</book>
</BookInfo>

//php ( vim book1.php )

<?php
$xml=Simplexml_load_file("book1.xml");
foreach( $xml → book as $b)
{
echo "bookno=$b -> bookno" ."<br>";
echo "bookname=$b -> bookname". "<br>";
echo "authorname=$b -> authorname"."<br>";
echo "price=$b -> price"·"<br>";
echo "year=$b -> year"."<br>";
echo "<br><br> Attributes:";
echo $b[0] ['bid'];
echo "<br>";
}
?>

// QUESTION - 2

//xml ( vim Movie.xml )

<?xml version="1.0" encoding="ISO-8859-1"?>


<Movieinfo>
<movie>
<movieno> 1 </movieno>
<moviename> ABCD </moviename>
<actorname> XYZ </actorname>
<release year> 2010 </release year>
</movie>
<movie>
<movieno> 2 </movieno>
<moviename> Raja </moviename>
<actorname> ABC </actorname>
<release year> 2005 </release year>
</movie>
<movie>
<movieno> 3 </movieno>
<moviename> Ashiqui </moviename>
<actorname> PQR </actorname>
<release year> 2000 </release year>
</movie>
<movie>
<movieno> 4 </movieno>
<moviename> Tanhaji </moviename>
<actorname> MNO </actorname>
<release year> 2018 </release year>
</movie>
<movie>
<movieno> 5 </movieno>
<moviename> Sairat </moviename>
<actorname> Prashant </actorname>
<release year> 2017 </release year>
</movie>
</Movieinfo>

//php ( vim Movie.php )

<?php
$dom=new DomDocument();
$dom -> load ("Movie.xml);
echo "<h2> Movie name </h2>";
<bname=$dom -> getElementsByTagName("Moviename");
foreach ($bnamme as $b)
{
echo "<b> $b -> textContent <br><br><br>";
}
echo "<h2> Actor name </h>";
$bname=$dom -> getElementsByTagName("actorname");
foreach ($bname as $b)
{
echo "<b> $b -> textContext <b><br><br>";
}
?>

# ASSIGNMENT 3 ( JavaScript and jquery ) #

// SET A

// QUESTION - 1
//html alert ( vim ass3a1a.html )

<!DOCTYPE html>
<html>
<body>
<h1>My first web page</h1>
<p>My first paragraph</p>
<script>
window.alert("Exams are near,have you started preparing for?");
</script>
</body>
</html>

//html prompt ( vim ass3a1b.html )

<!DOCTYPE html>
<html long "en">
<head>
<meta charset=utf-8>
<title> JavaScript prompt() example-2 </title>
</head>
<body>
<script type="text/javascript">
visiter_name=prompt(" Input your name:")
if(visiter_name !=null && visiter_name!=" ")
alert ("Your Name is :" +visiter_name);
else
alert ("Blank Name...!")
</script>
</body>
</html>

//html confirm ( vim ass3a1c.html )

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=utf-8>
<title>JavaScript confirm box example </title>
</head>
<body>
<h1 style="color: red">Exams are near,have you started preparing
for?</h1>
<hr />
<script type="text/javascript">
mess1='Press Ok to Continue.';
math=99;
x = confirm(mess1);
if (x == true)
{
alert("You have clicked on Ok Button.");
}
else
{
alert("You have clicked on Cancel Button."); }
</script>
</body>
</html>

// QUESTION - 2

//html ( vim ass3a2.html )

<!DOCTYPE html>
<html>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.
js"></script>
<script>
$(document).ready(function()
{
$("#btn1").click(function()
{
$("p").append(" <b>Newly added appended text</b>.");
});
$("#btn2").click(function(){
$("ol").append("<li><b>Newly added appended
item</b></li>");
});
});
</script>
</head>
<body>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<ol>
<li>Item no.1</li>
<li>Item no.2</li>
<li>Item no.3</li>
</ol>
<button id="btn1">Append text</button>
<button id="btn2">Append item</button>
</body>
</html>

// SET B

// QUESTION - 1
<html>
<head>
<body>
<script>
function validateform()
{
var name=document.myform.name.value;
var password=document.my.form.password.value;
if(name==null || name==")
{
alert ("Name can't be bank");
return false;
}
else if (password.length<6)
{
alert ("Password must be at least 6 characters long.");
return false;
}
}

</script>
<body>
<form name="myform" method="post"
action="http://www.javapoint.com/javascript pages /valid.jsp"
On submit="return validateform()">
Name: <input type="text" name="name"> </br>
password: <input type="password"name="password"> <br/>
<input type="Submit" value="register">
<form>
</body>

// QUESTION - 2

//html ( vim ass3b2.html )

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Inserting Multiple Elements Before or After the Elements in
jQuery</title>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script>
$(document).ready(function()
{
$("button").click(function()
{
var newHeading = "<h2>Important Note:</h2>";
var newParagraph = document.createElement("p");
newParagraph.innerHTML = "<em>It is very Beautiful...</em>";
var newImage = $('<img src="/root/MSS/S php
Practicals/Assignment 3/Set B/india.jpg" alt="Symbol">');
$("p").before(newHeading, newParagraph, newImage);
});
});

</script>
</head>
<body>
<button type="button">Insert Contents</button>
<p>Hello world</p>
</body>
</html>

# ASSIGNMENT 4 ( AJAX ) #

// SET A

// QUESTION - 1

<html>
<head>
<script type="text"/Javascript">
function point ()
{
var ob=false;
ob=new xmlhttpRequest();
ob.open("GET","a4a1.php?");
ob.send()
ob.onready StateChange=function()
{
if(ob.readyState=4 && ob.Status==200)
{
document.getElementById ("1"')inner
HTML=ob.responseText;
}
}
}
</script>
</head>
<body>
<center>
<h5>display content of contact.data file</h5>
<input type="button" value print
onclick="print()> <br><br>
<span id="t">
</span>
</center>

</body>
?/html>
<?php>
$fp=fopen
<?php
$fp=fopen('contact.plot a', 'r');
echo "<table border=1>";
echo "<tr><th> srno.</th><th> name </th><th> rno </th>
<th> mno </th><th> address </th></tr>
while ($row=fscarf($fp,%s,%s,%s,%s,%s))
{
echo "<tr>";
foreach($row astr)
{
echo "<tr>";
foreach ($row as $r)
{
echo "</td> $r </td>";
}
echo "</tr>";
}
echo "</table>";
Fclose ($fp);
}

// QUESTION 2

<html>
<head>
function show(str).
{
if (window.xml HttpRequest)
{
xmlhttp=new xmlHttpRequest();
}
else
{
xmlhttp=new ActiveObject("microsoft.xmlHTTP");
}
xmlhttp.onreadyStateChange=function()
{
if(xmlhttp.readyState= 4 && xmlhttp.status==200)
{
document.getElementById("t");
innerHTML=xmlhttp responserText;
}
}
xmlhttp.open ("GET","Http://localhost/ass4a2.php ?
name="+str,true);
xmlhttp send();
}
</script>

</head>
</body>
<form method="get">
Enter the name
<input type="text" onkeyup="show(this.value)")
</form>
<span id= "t">
</span>
</body>
</html>

<?php
$name=$_GET ["name"];
if ($name=='Ankita' || $name == 'Siddhi' || $name == 'Shrau' ||
$name == 'Aasavari' || $name == 'Payal');
{
echo "$name Hello master";
}
else if($ name==" ")
{
echo "stranger";
}
else
{
echo "$name I don't know you";
}
?>

// SET B

// QUESTION - 1

//Create TEACHER Table

<html>
<head>
function show (str)
{
if(window.xmlhttpRequest)
{
xmlhttp=new xmlhttpRequest()
}
else
{
xmlhttp=new ActiveObject ("microsoftxmlHTTP");
}
xml http.onreadyStateChange=function()
{
if(xmlhttp.readystate==4 && xmlhttpStatus==200)
{
document.getElementById("t")
innerHTML = xmlhttp.responseText;
}
xmlhttp.open("GET", "http://localhost/s.php:q = "
+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
form method="get">
enter teacher name:
<input type="text" onkeyup="show(this.value)">
<br>
</form>
<span id="t">
</body>
</html>

<?php
$q = $_GET ['q']
$can=pg_connect("host=localhost dbname=sss user=postgres")
or die ("can't connect");
$q= "select * from TEACHER where tname "$q";
$res=pg_query($con,$q);
while ($row=pg_fetch_row($resid))
{
echo "<br> Teacher no:". $row[o];
echo "<br> Teacher name:". $row[1];
echo "<br> Teacher qualification:". $row[2];
echo "<br> Teacher Salary:". $row[3];
}
?>

// QUESTION 2

<html>
<head>
<script>
function Show(str)
{
if(window.xmlHttpRequest()
{
xmlhttp=new xmlHttpRequest();
}
xmlhttp=new ActiveObject("microsoft xmlHTTP);
}
xmlhttp.onreadyStateChange=function()
{
if(xmlhttp.readyState== 4 && xmlhttp.status==200)
{
document.getElementById("t")
innerHTML= xmlhttp.responseText);
}
}
xmlhttp.open("GET","http://localhost border php ?q="+str
true);
xmlhttp.Send();
}

</script>
<head>
<body>
<form method ="get">
Enter customer name:
<input type= "text" onkeyup=" show(this value)">
<br>
</form>
<span id= "t">
</body>
</htmll>

<?php
$q = $_GET['q'];
$con=pg_connect ("host=localhost dbname=order user=postgues')
or
die("can't connect");
$q= "Select ord,ano,odate,saddr, from cast and where custcno=
ord con and (name="$q");
$res=pg_query($con, $q);
while ($row=pg_fetch_row($res))
{
echo "<br> orderno:".$row [0];
echo "<br> orderdate:".$row [1];
echo "<br> order address:". $row [2];
}
?>

You might also like