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

PHP Lab Manual

The document is a PHP lab manual for the V semester of the B.Sc. Computer Science program at D.N.R. College, Bhimavaram. It includes various PHP programming exercises such as generating Fibonacci series, checking for palindromes, demonstrating inheritance, creating registration forms, and managing cookies and sessions. Each exercise is accompanied by code snippets and expected outputs, providing a practical guide for students learning web application development using PHP and MySQL.

Uploaded by

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

PHP Lab Manual

The document is a PHP lab manual for the V semester of the B.Sc. Computer Science program at D.N.R. College, Bhimavaram. It includes various PHP programming exercises such as generating Fibonacci series, checking for palindromes, demonstrating inheritance, creating registration forms, and managing cookies and sessions. Each exercise is accompanied by code snippets and expected outputs, providing a practical guide for students learning web application development using PHP and MySQL.

Uploaded by

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

D.N.R.

COLLEGE (AUTONOMOUS): BHIMAVARAM


DEPARTMENT OF COMPUTER SCIENCE

WEB APPLICATION DEVELOPMENT BY USING PHP&MYSQL – 7A


LAB MANUAL
V SEMESTER
III B.SC(COMPUTER SCIENCE)
PHP LAB MANUAL
1. WRITE A PHP PROGRAM TO DISPLAY FIBONACCI SERIES
<!DOCTYPE html>
<html>
<body>
<?php
$num = 0;
$n1 = 0;
$n2 = 1;
echo "<h3>Fibonacci series for first 12 numbers: </h3>";
echo "\n";
echo $n1.' '.$n2.' ';
while ($num < 10 )
{
$n3 = $n2 + $n1;
echo $n3.' ';
$n1 = $n2;
$n2 = $n3;
$num = $num + 1;
}
?>
</body>
</html>
Output:

Department of Computer Science PHP LAB MANUAL Page 1


2. WRITE A PHP PROGRAM TO CHECK THE GIVEN NUMBER IS PALINDROME OR NOT
<!DOCTYPE html>
<html>
<body>
<?php
$num = 123454321;
$x = 0;
$n =$num;
while(floor($num))
{
$mod = $num%10;
$x = $x * 10 + $mod;
$num = $num/10;
}
if($n==$x)
{
echo "$n is a Palindrome number.";
}
else
{
echo "$n is not a Palindrome number.";
}
?>
</body>
</html>
Output: 121 is a Palindrome number.
3. WRITE A PHP PROGRAM FOR SINGLE INHERITANCE
<?php
class demo
{
public function display()
{
echo "Example of inheritance ";
}
}

Department of Computer Science PHP LAB MANUAL Page 2


class demo1 extends demo
{
public function view()
{
echo "in php";
}
}
$obj= new demo1();
$obj->display();
$obj->view();
?>
Output:
Example of inheritance
4. WRITE A PHP PROGRAM FOR MULTILEVEL INHERITANCE
<?php
class A
{
function showA()
{
echo "I am show method in A Class<br>";
}
}
class B extends A
{
function showB()
{
echo "I am show method in B Class<br>";
}
}
class C extends B
{
function showC()
{
echo "I am show method in C Class<br>";
}

Department of Computer Science PHP LAB MANUAL Page 3


}
$obj=new C;
$obj->showA();
$obj->showB();
$obj->showC();
?>
Output:
I am show method in A Class
I am show method in B Class
I am show method in C Class
5. WRITE A PHP PROGRAM FOR HIERARCHICAL INHERITANCE
<?php
// base class named "Jewellery"
class Jewellery
{
public function show()
{
echo 'This class is Jewellery ';
}
}
// Derived class named "Necklace"
class Necklace extends Jewellery
{
public function show()
{
echo 'This class is Necklace ';
echo"<br>";
}
}
// Derived class named "Necklace"
class Bracelet extends Jewellery
{
public function show()
{
echo 'This class is Bracelet ';

Department of Computer Science PHP LAB MANUAL Page 4


}
}
// creating objects of derived classes "Necklace" and "Bracelet"
$n = new Necklace();
$n->show();
$b = new Bracelet();
$b->show();
?>
Output:
This class is Necklace
This class is Bracelet
6. WRITE A PHP PROGRAM FOR INTERFACE IN PHP
<?php
interface circle
{
public function draw1();
}
interface rectangle
{
public function draw2();
}
class demo implements circle,rectangle
{
public function draw1()
{
echo "Drawing Circle";
echo "</br>";
}
public function draw2()
{
echo "Drawing Rectangle";
}
}
$obj= new demo();
$obj->draw1();

Department of Computer Science PHP LAB MANUAL Page 5


$obj->draw2();
?>
Output:
Drawing Circle
Drawing Rectangle
7. WRITE A PHP PROGRAM FOR CREATING REGISTRATION FROM
<HTML>
<head>
<title>REGISTRATION FORM</title>
</head>
<body bgcolor="CadetBlue">
<form action="action_page.php">
<h1 align="center"> REGISTRATION FORM </h1>
<p>Please fill in this form to create an account.</p>
<hr>
<label for="FullName"><b>Full Name</b></label>
<input type="text" name="Enter your Full Name" name="FullName" required>
<label for="email"><b>Email</b></label>
<input type="text" mail="Enter Email" name="email" required>
<label for="password"><b>Password</b></label>
<input type="password" password="Enter Password" name="password" required>
<label for="password-repeat"><b>Repeat Password</b></label>
<input type="password" password="Repeat Password" name="password-repeat" required>
<hr>
<p>By creating an account you agree to our <a href="#">Terms & Privacy</a>.</p>
<button type="submit" class="Register Button">Register</button>
</div>
<p>Already have an account? <a href="#">Sign in</a>.</p>
</div>
</form>
</body>
</html>

Department of Computer Science PHP LAB MANUAL Page 6


OUTPUT:

8. WRITE A PROGRAM FOR COMBINING HTML AND PHP CODE ON A SINGLE PAGE

<!doctype html>
<html>
<head>
<title>
Use a Php in Html
</title>
</head>
<body>
<h1>
<?php
echo " This is example program for combining HTML and PHP "
?>
</h1>
</body>
</html>

Department of Computer Science PHP LAB MANUAL Page 7


OUTPUT:

9. WRITE A PHP PROGRAM FOR CREATING COOKIES IN PHP

<?php
setcookie("user", "DNR");
?>
<html>
<body>
<?php
if(!isset($_COOKIE["user"]))
{
echo "Sorry, cookie is not found!";
}
else
{
echo "<br/>Cookie Value: " . $_COOKIE["user"];
}
?>
</body>
</html>
Department of Computer Science PHP LAB MANUAL Page 8
OUTPUT:

Firstly cookie is not set. But, if you refresh the page, you will see cookie is set now.

10. WRITE A PHP PROGRAM FOR CREATING SESSIONS IN PHP

//Save file as session1.php


<?php
session_start();

Department of Computer Science PHP LAB MANUAL Page 9


?>
<html>
<body>
<?php
$_SESSION["user"] = "DNR";
echo "Session information are set successfully.<br/>";
?>
<a href="session2.php">Visit next page</a>
</body>
</html>
//Save file as session2.php
<?php
session_start();
?>
<html>
<body>
<?php
echo "User is: ".$_SESSION["user"];
?>
</body>
</html>
OUTPUT:

Department of Computer Science PHP LAB MANUAL Page 10


11. WRITE A PHP PROGRAM TO DRAW DIFFERENT IMAGES.
<?php
header("Content-type: image/png");
$img_width = 800;
$img_height = 600;
$img = imagecreatetruecolor($img_width, $img_height);
$black = imagecolorallocate($img, 0, 0, 0);
$white = imagecolorallocate($img, 255, 255, 255);
$red = imagecolorallocate($img, 255, 0, 0);
$green = imagecolorallocate($img, 0, 255, 0);
$blue = imagecolorallocate($img, 0, 0, 255);
$orange = imagecolorallocate($img, 255, 200, 0);
imagefill($img, 0, 0, $white);
imagerectangle($img,$img_width*2/10, $img_height*5/10, $img_width*4/10, $img_height*8/10, $red);
imagerectangle($img,$img_width*4/10, $img_height*5/10, $img_width*8/10, $img_height*8/10, $red);
imagepolygon($img,[$img_width*3/10,$img_height*2/10,$img_width*2/10,$img_height*5/10,$img_widt
h*4/10, $img_height*5/10], 3, $red);
imageopenpolygon($img,[$img_width*3/10,$img_height*2/10,$img_width*7/10,$img_height*2/10,
$img_width*8/10, $img_height*5/10], 3, $red);
imageellipse($img, 100, 100, 100, 100, $orange);
imagearc($img, $img_width*3/10, $img_height*8/10, 100, 200, 180, 360, $red);
imageline($img, 0, $img_height*8/10, $img_width, $img_height*8/10, $green);

Department of Computer Science PHP LAB MANUAL Page 11


imagepng($img);
?>
OUTPUT:

Department of Computer Science PHP LAB MANUAL Page 12

You might also like