Updated Practical Slips Solutions Sem
Updated Practical Slips Solutions Sem
Slip 1: Write a PHP script to keep track of number of times the web page has been accessed (Use
Session Tracking).
Solution:
<?php
session_start();
if(isset($_SESSION['page_views'])){
$_SESSION['page_views']++;
} else {
$_SESSION['page_views'] = 1;
}
echo "You have visited this page " . $_SESSION['page_views'] . " times.";
?>
=====================================================================
====
Slip 2: 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 (Use Cookies).
Solution:
HTML file :
<html>
<body>
<form action="slip2.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>
=====================================================================
====
Slip 3: Write a PHP script to accept username and password. If in the first three chances,
username and password entered is correct then display second form with “Welcome message”
otherwise display error message. [Use Session]
Solution:
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","Slip3.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>
=====================================================================
====
Slip 4: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]
Solution:
HTML file :
<html>
<body>
<form action="Slip4.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>
=====================================================================
====
Slip 5:Create XML file named “Item.xml”with item-name, item-rate, item quantity Store the
details of 5 Items of different Types
Solution:
=====================================================================
====
Slip 6: Write PHP script to read “book.xml” file into simpleXML object. Display attributes and
elements. ( simplexml_load_file() function )
Solution:
=====================================================================
====
Slip 7: Write a PHP script to read “Movie.xml” file and print all MovieTitle and ActorName of
file using DOMDocument Parser. “Movie.xml” file should contain following information with at
least 5 records with values. MovieInfoMovieNo, MovieTitle, ActorName ,ReleaseYear
Solution:
// Loop through each <MovieInfo> element and print the MovieTitle and ActorName
foreach ($movieInfos as $movieInfo) {
$movieTitle = $movieInfo->getElementsByTagName('MovieTitle')->item(0)->nodeValue;
$actorName = $movieInfo->getElementsByTagName('ActorName')->item(0)->nodeValue;
echo "Movie Title: $movieTitle\n";
echo "Actor Name: $actorName\n\n";
}
?>
=====================================================================
====
Slip 8: Write a JavaScript to display message ‘Exams are near, have you started preparing for?’
(usealert box ) and Accept any two numbers from user and display addition of two number .(Use
Prompt and confirm box)
Solution:
=====================================================================
====
Slip 9 : Write a JavaScript function to validate username and password for a membership form.
Solution:
function validateForm() {
const username = document.forms["membershipForm"]["username"].value;
const password = document.forms["membershipForm"]["password"].value;
=====================================================================
====
Slip 10: Create a HTML fileto insert text before and after a Paragraph using jQuery.
[Hint : Use before( ) and after( )]
Solution:
<!DOCTYPE html>
<html>
<head>
<title>Insert Text Before and After Paragraph Using jQuery</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<p id="my-paragraph">This is my paragraph.</p>
<script>
// insert text before the paragraph
$("#my-paragraph").before("<p>Here's some text before the paragraph.</p>");
=====================================================================
====
Slip 11: Write a Javascript program to accept name of student, change font color to red, font size
to 18 if student name is present otherwise on clicking on empty text box display image which
changes its size (Use onblur, onload, onmousehover, onmouseclick, onmouseup)
Solution:
<!DOCTYPE html>
<html>
<head>
<title>Student Name</title>
<script>
function changeStyle() {
var name = document.getElementById("name");
if (name.value != "") {
name.style.color = "red";
name.style.fontSize = "18px";
} else {
var image = document.getElementById("image");
image.style.display = "block";
}
}
function changeSize() {
var image = document.getElementById("image");
image.style.width = "200px";
image.style.height = "200px";
}
function resetSize() {
var image = document.getElementById("image");
image.style.width = "100px";
image.style.height = "100px";
}
</script>
</head>
<body>
<h1>Student Name</h1>
<input type="text" id="name" onblur="changeStyle()">
<br><br>
<img id="image" src="https://picsum.photos/id/237/100/100" onclick="changeSize()"
onmouseup="resetSize()" onmouseover="changeSize()" onmouseout="resetSize()"
style="display:none;">
</body>
</html>
==============================================================
Slip 12: 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]
Solution:
HTML file :
<html>
<head>
<style>
span
{
font-size: 25px;
}
table
{
color: blueviolet; ;
}
</style>
<script type="text/javascript" >
function print()
{
var ob=false;
ob=new XMLHttpRequest();
ob.open("GET","slip12.php?");//emailid="+eid);
ob.send();
ob.onreadystatechange=function()
{
if(ob.readyState==4 && ob.status==200)
{
document.getElementById("i").innerHTML=ob.responseText;
}
}
}
</script>
</head>
<body>
<center>
<h3>Display the contents of a contact.dat file </h3>
<br><input type="button" value=Print onclick="print()" >
<span id="i"></span>
</center>
</body>
</html>
Dat file : contact.dat
1 Isha 65768798 98765432 Daughter
2 Megha 65235689 87654329 Mother
=====================================================================
====
Slip13: Write AJAX program where the user is requested to write his or her name in a text box,
and the server keeps sending back responses while the user is typing. If the user name is not
entered then the message displayed will be, “Stranger, please tell me your name!”. If the name is
Rohit, Virat, Dhoni, Ashwin or Harbhajan , the server responds with “Hello, master !”. If the
name is anything else, the message will be “, I don’t know you!”
Solution:
if ($name == "") {
echo "";
} else if ($name == "Rohit" || $name == "Virat" || $name == "Dhoni" || $name == "Ashwin" ||
$name == "Harbhajan") {
echo "Hello, master !";
} else {
echo "";
}
?>
=====================================================================
====