0% found this document useful (0 votes)
48 views

web tech IIsolution

The document contains multiple PHP scripts demonstrating various functionalities such as session management, cookie usage, and AJAX implementation. It includes examples for tracking page visits, changing web page preferences, user authentication, employee details management, reading XML files, and displaying data from a text file in a tabular format. Each slip provides HTML and PHP code for specific tasks, showcasing practical applications of PHP in web development.

Uploaded by

thirdeye353
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

web tech IIsolution

The document contains multiple PHP scripts demonstrating various functionalities such as session management, cookie usage, and AJAX implementation. It includes examples for tracking page visits, changing web page preferences, user authentication, employee details management, reading XML files, and displaying data from a text file in a tabular format. Each slip provides HTML and PHP code for specific tasks, showcasing practical applications of PHP in web development.

Uploaded by

thirdeye353
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Slip-1

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 file : slip21_2_1.php

<?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>

PHP file : slip21_2_2.php


<?php
$style = $_COOKIE['set1'];
$color = $_COOKIE['set2'];
$size = $_COOKIE['set4'];
$b_color = $_COOKIE['set3'];
$msg = "NR Classes";
echo "<body bgcolor=$b_color>";
echo "<font color=$color size=$size>$msg";
echo "</font></body>";
?>
Slip 3
1. 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].

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 file : error.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>

PHP file : slip_18_2_1.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="slip18_2_2.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 file : slip18_2_2.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>";
?>
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

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

<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

$xml=simplexml_load_file("Book.xml") or die("cannnot load");

$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>

<script type="text/javascript" >

function print()

var ob=false;

ob=new XMLHttpRequest();

ob.open("GET","slip14_Q2.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

PHP file :
<?php

$fp = fopen('contact.dat','r');

echo "<table border=1>";

echo "<tr><th>Sr. No.</th><th>Name</th><th>Residence No.</th><th>Mob.


no.</th><th>Relation</th></tr>";

while($row = fscanf($fp,"%s %s %s %s %s"))

echo "<tr>";

foreach($row as $r)

echo "<td>$r</td>";

echo "</tr>";

echo "</table>";

fclose($fp);

You might also like