PHP Lab Programs
PHP Lab Programs
PHP Lab Programs
Login.html
<html>
<head><title>Login page</title>
</head>
<body>
<center>
<h1>LOGIN FORM</h1>
<table>
<tr>
<td><label>USERNAME:</label></td>
</tr>
<tr>
<td><label>PASSWORD:</label></td>
</tr>
<tr>
</tr>
</table>
</form>
</center>
</body>
</html>
verify_login.php
<?php
$myxml=simplexml_load_file("userlogin.xml");
$uname=$_REQUEST['uname'];
$pwd=$_REQUEST['pwd'];
$xmluname="";
$xmlpwd="";
for($i=0;$i<count($myxml);$i++)
{$xmluname=$myxml->user[$i]->uname;
$xmlpwd=$myxml->user[$i]->pwd;
if($xmluname==$uname&&$xmlpwd==$pwd)
die();
}}
?>
userlogin.xml
<users><user>
<uname>vvvv</uname>
<pwd>123</pwd>
</user>
<user>
<uname>aaaa</uname>
<pwd>abcd</pwd>
</user>
<user>
<uname>hhhh</uname>
<pwd>xyz</pwd>
</user>
</users>
Cal.html
<html>
<head>
<title>calculator</title></head>
<br><br><center><h1>Basic calculator</h1><br>
</center>
</html>
Exec.php
<?php
$x=$_REQUEST['v1'];
$y=$_REQUEST['v2'];
if(isset($_POST['add']))
elseif(isset($_POST['sub']))
elseif(isset($_POST['mul']))
elseif(isset($_POST['div']))
elseif(isset($_POST['mod']))
}
?>
3. Modify the above program such that it stores each query in a database and checks the
database first for the result. If the query is already available in the DB, it returns the
value that was previously computed (from DB) or it computes the result and returns it
after sorting the new query and result in DB.
<html>
<head>
<title>calculator</title></head>
<br><br><center><h1>Basic calculator</h1><br>
</form>
</center>
</html>
Insert.php
<?php
$x=$_REQUEST['v1'];
$y=$_REQUEST['v2'];
if(isset($_POST['add']))
{$op='+';
$res=($x+$y);
elseif(isset($_POST['sub']))
{ $op='-';
$res=($x-$y);
elseif(isset($_POST['mul']))
{ $op='*';
$res=($x*$y);
elseif(isset($_POST['div']))
{ $op='/';
$res=($x/$y);
elseif(isset($_POST['mod']))
{ $op='% ';
$res=($x%$y);
$con=mysqli_connect('localhost',"root","");
$db=mysqli_select_db($con,"veda") or die(mysqli_error());
$numrows=mysqli_num_rows($query);
if($numrows!=0)
{ while($row=mysqli_fetch_array($query))
{$val1=$row['v1'];
$val2=$row['v2'];
$oper=$row['oper'];
$result=$row['res'];
if($val1==$x&&$val2==$y&&$op==$oper)
}}
else
}?>
4. A web application takes a name as input and on submit it shows a hello<name> page
where <name>is taken from the request. It shows the start time at the right top corner
of the page and provides a logout button. On clicking this button, it should show a
logout page with Thank You <name> message with the duration of usage(hint: Use
session to store name and time).
Sess.html
<html>
<body><center><h1>LOGIN PAGE</h1><br><br>
</form></center>
</body>
</html>
Sess.php
<?php
session_start();
$name=$_POST['uname'];
$_SESSION['uname']=$name;
$time=time();
echo"<p align='right'>$time</p>";
$_SESSION['time']=time();
?>
</form>
Log.php
<?php
session_start();
$nowSince=time()-$_SESSION['time'];
$name=$_SESSION['uname'];
session_destroy();
?>
5. A web application that takes name and age from an HTML page. If the age is less than
18, it should send a page with “Hello <name>, you are not authorized to visit this site”
message, where <name>should be replaced with the entered name. Otherwise it should
send “Welcome <name> to this site” message.
Acces.html
<html>
<head>
<title>Acess</title></head>
<body>
<br><br><center><h1>User Eligibilty</h1><br>
</form>
</center>
</body>
</html>
Check.php
<?php
$age=$_REQUEST['age'];
$names=$_REQUEST['names'];
if($age<=18)
echo '<h1>Hello',' ',$names,' ',',you are not authorised to visit this site</h1>';
else
}?>
6. A web application that lists all cookies stores in the browser on clicking “List Cookies”
button. Add cookies if necessary.
Cookie_set.php
<?php
$exp=time()+86400;
setcookie("abc","123",$exp);
setcookie("def","456",$exp);
setcookie("aaa","bbb",$exp);
?>
Cookie.php
<center>
<br><br>
</form>
</center>
<?php
error_reporting(0);
if($_POST['list'])
{foreach($_COOKIE as $key=>$val)
echo"<center>".$key."is at".$val."<br></center>";
?>