Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
73 views29 pages

II BCA A PHP Lab Practical Print Final NEW

MSU php lab programs

Uploaded by

rbsiva421688
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views29 pages

II BCA A PHP Lab Practical Print Final NEW

MSU php lab programs

Uploaded by

rbsiva421688
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

DEPARTMENT OF COMPUTER SCIENCE

2024 – 2025

NAME :

REG NO :

CLASS : II BCA Batch I

SUBJECT : PHP PROGRAMMING LAB

SUBJECT CODE : ESCAP1


DEPARTMENT OF COMPUTER SCIENCE

Reg.No: Class: I BCA Batch I

Certified bonafide record of work done by ________________________________


in the PHP PROGRAMMING LAB, KAMARAJ COLLEGE,
THOOTHUKUDI, during the year 2024 –2025.

STAFF INCHARGE HEAD OF THE DEPARTMENT

Submitted for the practical examination held on


at KAMARAJ COLLEGE, THOOTHUKUDI.

EXAMINERS

I.

II.
CONTENTS

PAGE
S.NO DATE TITLE SIGNATURE
NO.

1 Greeting Text

2 Palindrome Checking

Armstrong Number
3 Checking

4 Program Using Function

Login Page Without SQL


5
Connection

6 Array Manipulation

7 Personal Information

Login Page with SQL


8
Connection
Product Advertisement
9
with Image and Audio

10 Login Using Session


GREETING TEXT

<html>
<head>
<title></title>
</head>
<body>
<form method='POST'>
<h2>Please input your name:</h2>
<input type="text" name="name">
<input type="submit" value="Submit Name">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST" &&isset($_POST['name']))
{
$name = $_POST['name'];
echo "<h3> Hello $name </h3>";
}
?>
</body>
</html>
OUTPUT

Hello world
PALINDROME CHECKING

<html>
<body>
<form method="post">
Enter the String:
<input type="text" name="str">
<input type="submit" value="Submit">
</form>
<?php
if($_POST)
{
$MyString = $_POST['str'];
$revString = strrev($MyString);
if ($revString == $MyString){
echo $MyString." is a Palindrome string.\n";
} else {
echo $MyString." is not a Palindrome string.\n";
}
}
?>
</body>
</html>
OUTPUT

Madam is a Palindrome string

Apple is not a Palindrome string


ARMSTRONG NUMBER CHECKING

<html>
<body>
<form method="post">
Enter the Number:
<input type="number" name="number">
<input type="submit" value="Submit">
</form>
<?php
if($_POST)
{
$number = $_POST['number'];
$a = $number;
$sum = 0;
while( $a != 0 )
{
$rem = $a % 10; //find reminder
$sum = $sum + ( $rem * $rem * $rem );
$a = $a / 10;
}
if( $number == $sum )
{
echo "Yes $number is an Armstrong Number";
}
else
{
echo "$number is not an Armstrong Number";
}
}
?>
</body>
</html>
OUTPUT

Yes,153 is an Armstrong number

123 is not an Armstrong number


PROGRAM USING FUNCTION
<html>
<head>
<title> Factorial Program</title>
</head>
<body>
<form method="POST">
<center>
<label>Enter a number</label>
<input type="text" name="number" /><br>
<input type="submit" name="submit" value="Submit" />
</center>
</form>
<?php
function Factorial($n)
{
$fact = 1;
for ($i = 1; $i<= $n; $i++)
{
$fact = $fact * $i;
}
return $fact;
}
if($_POST['submit'] == "Submit")
{
$n = $_POST['number'];
$fact = Factorial($n);
echo '<br>'. 'The factorial of the number '.$n .' is ' . $fact;
}
?>
</body>
</html>
OUTPUT

The factorial of 5 is 120


LOGIN PAGE WITHOUT SQL CONNECTION

First.php

<html>
<head>
<title>Login Page</title>
</head>
<body>
<h2>Login Page</h2>
<form action="login.php" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required><br><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required><br><br>
<input type="submit" value="Login">
</form>
</body>
</html>

Login.php

<?php
$correct_username = "admin";
$correct_password = "kcsfcs24";
$username = $_POST['username'];
$password = $_POST['password'];
if ($username === $correct_username&& $password === $correct_password)
{
echo "Login successful. Welcome, $username!";
}
else
{
echo "Invalid username or password.";
}
?>
OUTPUT
ARRAY MANIPULATION

<?php
$a=array("maths","crypt","php","ds","mm");
$b=$a;
$n=array("60","80","95","40","55");
echo'<h1 align="center"><u>Array Manipulation</u></h1>';
echo'<b><u>Given Array:</u><br>&nbsp; a=';
print_r($a);
echo'<br><b><u>Array copy to b():</u><br>&nbsp; b=';
print_r($b);
echo'<br><b><u>Given Integer Array:</u><br>&nbsp; n=';
print_r($n);
echo'</b><br><h3><font color="darkbrown">Ascending Order of an array
a()&nbsp;&nbsp;:</font></h3>';
sort($a);
print_r($a);
echo'<br><h3><font color="green">Decending order of an array
a()&nbsp;&nbsp;:</font></h3>';
rsort($a);
print_r($a);
echo'<br><h3><font color="darkgreen">Array Slicing in a()
&nbsp;&nbsp;&nbsp;&nbsp;:</font></h3>';
print_r(Array_slice($a,2));
echo'<br><h3><font color="dodgerblue">Array Splicing in b()
&nbsp;&nbsp;:</font></h3>';
print_r(Array_splice($b,2,4,$n));
echo'<br><h3><font color="chocolate">Array Poping from a():</font></h3>';
echo'<b>Before :</b>';
print_r($a);
Array_pop($a);
echo'<br><b>After &nbsp; :</b>';
print_r($a);
echo'<br><h3><font color="lime">Array Pushing into n():</font></h3>';
echo'<b>Before :</b>';print_r($n);
Array_push($n,"50","30");
echo'<br><b>After &nbsp; :</b>';
print_r($n);
echo'<br><h3><font color="gold">Addition of n() Element:</font></h3>Sum=';
$n=Array_sum($n);
print_r($n);
?>
OUTPUT
PERSONAL INFORMATION

<html>
<body>
<form action="display.php" method="POST">
<h1>Biodata</h1>
Name:<input type=text name="name1"><br><br>
Address: <textarea name=address></textarea><br><br>
Age: <input type=text name=age><br><br>
Phone: <input type=text name=phone><br><br>
Email: <input type=text name=email><br><br>
Educational Qualification:<input type=text name=qualification><br>
<input type=submit value=Display><br><br>
</form>
</body>
</html>
<?php
if ($_POST) {
echo "<h1>PERSONAL DETAILS</h1>";
echo "Name: " . $_POST["name1"] . "<br>";
echo "Address: " . $_POST["address"] . "<br>";
echo "Age: " . $_POST["age"] . "<br>";
echo "Mobile: " . $_POST["phone"] . "<br>";
echo "Email: " . $_POST["email"] . "<br>";
echo "Qualification: " . $_POST["qualification"] . "<br>";
}
?>
OUTPUT
LOGIN PAGE WITH SQL CONNECTION

dbhome.php
<html>
<body>
<form action="sql.php" method="post">
<br><center><table border=2" bordercolor="red">
<tr><td><table><tr font face="white">
<thcolspan="2" bgcolor="crimson" align="center">
<h3>LOGIN FORM</th></tr>
<tr><th align="left">UserName</th>
<td><input type="text" name="u"></td></tr>
<tr><th align="left">Password</th>
<td><input type="password" name="p"></td></tr>
<tr align="center"><br><td><input type="submit" value="
LOGIN "></td><td><input type="reset" value=" CLEAR
"></td></tr>
</table></td></tr></table>
</center></form></body></html>

sql.php
<?php
$un=$_POST['u'];
$pd=$_POST['p'];
$con=0;
$servername = "localhost";
$username = "root";
$password = "";
$db="dblogin";
$conn = new mysqli($servername, $username,
$password, $db); if (!$conn)
{
die("Connection failed: " . mysqli_connect_error());

}
$res=mysqli_query($conn,"SELECTuname,pword FROM login");
while($row=mysqli_fetch_array($res))
{
if($un==$row["uname"] && $pd==$row["pword"])
{
$con=1;
}
}
if($con==1)
{
echo"<font color='blue' size='5' align='center'>Welcome
$un </font>";
}
else
{
echo"<font color='red' size='5' align='center'>Invalid Username or
Password</font>"; }
?>
OUTPUT:
PRODUCT ADVERTISEMENT WITH IMAGES AND AUDIO

<html>
<body>
<bgsound src="bgm.mp3">
<!-- Display Product Image --><center><p><b><font size=15 color='red' >DELL
INSPIRON-5463</b></font></p><br>
<table><tr><td>
<ul>
<u><h2>Spec & features:</h2></u>
<li>Processor: Intel i3-1215U (to 4.40 GHz), 6 Cores & 10MB Cache </li>
<li>RAM & Storage: 8GB, 8Gx1, DDR4, 2666MHz Ach & 512GB SSD
</li>
<li> Keyboard & Warranty: Standard Keyboard & 1 Year Onsite Hardware
Service
</li>
<li>Ports: 2 USB 3.2
</li>
</ul>
<center>
<audio controls>
<source src="music.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
</center>
</table></center>
<p><font color='white' size=5><b>Our Services</b>
<center>
<table cellspacing=20>
<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<img src="d1.webp" width="200" height="200">
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="d2.jpeg"
width="200" height="200">
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="d3.jpeg"
width="200" height="200">
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="d4.jpeg"
width="200" height="200"></tr>
</table>
</center>
<hr> <p align='center'><font color='red' size=5>CONTACT</font>
<font color='black'> <center><b>DELL COMPUTERS, THOOTHUKUDI. Ph.NO:
80125 51220</b><hr>
</body>
</html>
OUTPUT
LOGIN USING SESSION

1. loginsession.php
<?php
session_start();
$Cusername = 'II BCA A';
$Cpassword = 'kcsfcs';
if ($_SERVER['REQUEST_METHOD'] == 'POST' &&isset($_POST['username']))
{
$username = $_POST['username'];
$password = $_POST['password'];
if ($username == $Cusername&& $password == $Cpassword)
{ $_SESSION['user'] = $username;
$_SESSION['start'] = time();
$_SESSION['expire'] = $_SESSION['start'] + (1*60) ;
header('Location: dashboard.php');
} else
{
echo "<p style='color:red;'>Invalid username or password!</p>"; }
}
?>
<html>
<head>
<title>Login</title>
</head>
<body>
<center><h1>Login</h1>
<h2><form method="POST">
USER NAME<input type="text" name="username"
placeholder="Username" required><br><br>
PASSWORD<input type="password" name="password"
placeholder="Password" required><br><br>
<button type="submit">Login</button>
</form></h2>
</body>
</html>

2. Dashboard.php
<?php
session_start();
if (!isset($_SESSION['user'])) {
echo " Your session started";
}
else
{
$now = time();
if($now > $_SESSION['expire'])
{
session_destroy();
echo "<p align='center'>Your session has expire ! <a
href='loginsession.php'>Login Here</a></p>";
}
}
?>
<html>
<head>
<title>Dashboard</title>
</head>
<body>
<h2>Welcome, <?php echo $_SESSION['user']; ?>!</h2> <h3><p>You are now
logged in. Your session started.<br> Your Session Will destroy after 1
minute.<br> if you want to logout before 1minutes click on logout link. </p></h3>
<a href="logout.php">Logout</a>
</body>
</html>

3. Logout.php
<?php
<?php
session_start();
session_destroy();
echo "<p align='center'><H2>Your session has expired !</p>"; exit();
?>
OUTPUT

You might also like