web tech IIsolution
web tech IIsolution
1. Write a PHP script to keep track of number of times the web page has been
access. [Use session and cookies]
PHP file :
<html>
<head>
<title> Number of times the web page has been viited.</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'];
?>
Slip 2
1.Write a PHP script to change the preferences of your web page like font style,
font size, font color, background color using cookie. Display selected setting on
next web page and actual implementation (with new settings) on third page.
HTML file :
<html>
<body>
<form action="slip21_2_1.php" method="get">
<center>
<b>Select font style :</b><input type=text name=s1> <br>
<b>Enter font size : </b><input type=text name=s><br>
<b>Enter font color : </b><input type=text name=c><br>
<b>Enter background color :</b> <input type=text name=b><br>
<input type=submit value="Next">
</center>
</form>
</body>
</html>
<?php
echo "style is ".$_GET['s1']."<br>color is ".$_GET['c']."<br>Background
color is ".$_GET['b']."<br>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);
?>
<html>
<body>
<form action="slip21_2_2.php">
<input type=submit value=OK>
</form>
</body>
</html>
HTML file :
<html>
<head>
<script>
function getans()
{
st1=document.getElementById('txtname').value;
st2=document.getElementById('txtpass').value;
ob=new XMLHttpRequest();
ob.onreadystatechange=function()
{
if(ob.readyState==4 && ob.status==200)
{
if(ob.responseText==3)
{
alert("sorry you lost
the chances to login");
location="error.html";
}
else
if(ob.responseText=="correct")
{
alert("you entered
correct details");
}
else alert(ob.responseText);
}
}
ob.open("GET","slip8_Q2.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 file :
<?php
session_start();
$nm=$_GET['n'];
$ps=$_GET['p'];
if($nm==$ps)
{
echo "correct";
}
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";
}
?>
Slip 4
1. Write a PHP script to accept Employee details (Eno, Ename, Address) on first
page. On second page accept earning (Basic, DA, HRA). On third page print
Employee information (Eno, Ename, Address, Basic, DA, HRA, Total) [ Use
Session]
HTML file :
<html>
<body>
<form action="slip18_2_1.php" method="get">
<center> <h2>Enter Enployee Details :</h2> <br>
<table>
<tr> <td><b>Emp no :</b></td> <td><input type=text
name=eno></td> </tr>
<tr> <td><b> Name :</b></td> <td><input type=text
name=enm></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>
$_SESSION['eno'] = $eno;
$_SESSION['enm'] = $enm;
$_SESSION['eadd'] = $eadd;
?>
<html>
<body>
<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>
$total = $e1+$e2+$e3;
echo "<h2>Total Of Earnings Is : ".$total."</h2>";
?>
Slip 6
Q. 1) Write PHP script to read “book.xml” file into simpleXML object.
Display attributes and elements .
( simple_xml_load_file() function )
Book.XML
<ABCBOOK>
<Technical>
<BOOK>
<Book_PubYear>ABC</Book_PubYear>
<Book_Title>pqr</Book_Title>
<Book_Author>400</Book_Author>
</BOOK>
</Technical>
<Cooking>
<BOOK>
<Book_PubYear>ABC</Book_PubYear>
<Book_Title>pqr</Book_Title>
<Book_Author>400</Book_Author>
</BOOK>
</Cooking>
<Yoga>
<BOOK>
<Book_PubYear>ABC</Book_PubYear>
<Book_Title>pqr</Book_Title>
<Book_Author>400</Book_Author>
</BOOK>
</Yoga>
</ABCBOOK>
Book.php
<?php
$xmlstring=$xml->asXML();
echo $xmlstring;
?>
Slip 12
Q. 1)Write AJAX program to read contact.dat file and print the contents of the file in a tabular
format when the user clicks on print button. Contact.dat file should contain srno, name,
residence number,mobile number, Address. [Enter at least 3 record in contact.dat file]
HTML file :
<html>
<head>
<style>
span
font-size: 25px;
table
color: blueviolet; ;
</style>
function print()
var ob=false;
ob=new XMLHttpRequest();
ob.open("GET","slip14_Q2.php?");//emailid="+eid);
ob.send();
ob.onreadystatechange=function()
{
document.getElementById("i").innerHTML=ob.responseText;
</script>
</head>
<body>
<center>
<span id="i"></span>
</center>
</body>
</html>
PHP file :
<?php
$fp = fopen('contact.dat','r');
echo "<tr>";
foreach($row as $r)
echo "<td>$r</td>";
echo "</tr>";
echo "</table>";
fclose($fp);