PHP Pratical File
PHP Pratical File
Institutes
Semester: -5th
Programming in PHP Laboratory
UGCA1930
Practical file
Name: Aryan
Class: BCA-3’C’
Roll_No:2223152
1
Submitted To: Miss Punita Mam
Page .n
Sr.no Title o Sign's
Take values from the user and compute sum,
subtraction, multiplication, division and exponent of
1 value of the variables. 3
Write a program to find area of following shapes:
circle, rectangle, triangle, square, trapezoid and
2 parallelogram. 4-6
3 Compute and print roots of quadratic equation. 6,7
Write a program to determine whether a triangle is
4 isosceles or not? 8
Print multiplication table of a number input by the
5 user. 9
Calculate sum of natural numbers from one to n
6 number. 10
Print Fibonacci series up to n numbers e.g. 0 1 1 2 3
7 5 8 13 21…..n 11
Write a program to find the factorial of any number.
8 12
9 Determine prime numbers within a specific range. 13,14
Write a program to compute, the Average and
10 Grade of student’s marks. 15,16
Compute addition, subtraction and multiplication of
11 a matrix. 17-20
Count total number of vowels in a word “Develop &
12 Empower Individuals”. 21
13 Determine whether a string is palindrome or not? 22
14 Display word after Sorting in alphabetical order. 23
Check whether a number is in a given range using
15 functions. 24,25
Write a program accepts a string and calculates
number of upper-case letters and lower-case letters
16 available in that string. 26,27
Design a program to reverse a string word by word.
17 28
Write a program to create a login form. On
submitting the form, the user should navigate to
18 profile page. 29-34
Design front page of a college or department using
19 graphics method. 35-38
20 Write a program to upload and download files. 39-42
2
Pratical-1
<?php
$x=100;
$y=60;
?>
3
Pratical-2
Circle
Rectangle
Triangle
Square
Trapezoid
Parallelogram
<?php
function areaOfCircle($radius) {
function areaOfSquare($side) {
4
return pow($side, 2);
?>
5
Pratical-3
<?php
$d = $b**2 - 4*$a*$c;
if ($d > 0) {
} else if ($d == 0) {
return [$root];
} else {
return [];
6
}
$a = -19;
$b = 29;
$c = 50;
?>
7
Pratical-4
<?php
$side1 = 5;
$side2 = 5;
$side3 = 3;
} else {
?>
8
Pratical-5
<?php
$table = 10;
$length = 10;
$i = 1;
?>
9
Pratical-6
<?php
$N = 5;
$sum = 0;
?>
10
Pratical-7
Print the Fibonacci Series from up to n numbers e.g. 0 1 1 2
3 5 8………n.
<?php
function fibonacciSeries($n){
$num1 = 0;
$num2 = 1;
$num1 = $num2;
$num2 = $num3;
$n = 10;
fibonacciSeries($n);
?>
11
Pratical-8
<?php
$n = 5;
$f = 1;
$f = $f * $i;
?>
12
Pratical-9
<?php
$count = 0;
$num = 2;
$div_count=0;
if (($num%$i)==0)
$div_count++;
if ($div_count<3)
13
$count=$count+1;
$num=$num+1;
?>
14
Pratical-10
<?php
function calculateMarks($marks) {
$total = array_sum($marks);
$grade = "A";
$grade = "B";
$grade = "C";
$grade = "D";
} else {
$grade = "F";
return [
15
'total' => $total,
];
$results = calculateMarks($marks);
?>
16
Pratical-11
Addition
<?php
$matrixA = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
];
$matrixB = [
[9, 8, 7],
[6, 5, 4],
[3, 2, 1]
];
function printMatrix($matrix) {
foreach ($matrix as $row) {
echo implode(" ", $row) . "\n";
}
}
17
echo "Addition Result:"."\n";
printMatrix($additionResult);
?>
Subtraction
<?php
$matrixA = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
];
$matrixB = [
[9, 8, 7],
[6, 5, 4],
[3, 2, 1]
];
18
$subtractionResult = subtractMatrices($matrixA, $matrixB);
function printMatrix($matrix) {
foreach ($matrix as $row) {
echo implode(" ", $row) . "\n";
}
}
?>
Multiplication
<?php
$matrixA = [
[1, 2, 3],
[4, 5, 6],
19
[7, 8, 9]
];
$matrixB = [
[9, 8, 7],
[6, 5, 4],
[3, 2, 1]
];
function printMatrix($matrix) {
foreach ($matrix as $row) {
echo implode(" ", $row) . "\n";
}
}
?>
20
Pratical-12
<?php
function countVowels($str)
{
$str = strtolower($str);
$vowelCount = 0;
return $vowelCount;
}
?>
21
Pratical-13
<?php
function isPalindrome($string) {
$reversedString = strrev($cleanedString);
if (isPalindrome($testString)) {
} else {
?>
22
Pratical-14
<?php
function sortWords($inputString) {
});
$sortedWords = sortWords($inputString);
?>
23
Pratical-15
<?php
return true;
} else {
return false;
$number = 500;
$minRange = 100;
$maxRange = 1000;
} else {
24
}
?>
25
Pratical-16
<?php
function countCaseLetters($inputString) {
$upperCaseCount = 0;
$lowerCaseCount = 0;
if (ctype_upper($inputString[$i])) {
$upperCaseCount++;
elseif (ctype_lower($inputString[$i])) {
$lowerCaseCount++;
return [
26
];
$result = countCaseLetters($inputString);
?>
27
Practical-17
<?php
function reverseStringWordByWord($inputString) {
$reversedArray = array_reverse($wordsArray);
return $reversedString;
$reversedString = reverseStringWordByWord($inputString);
?>
28
Practial-18
Username: admin
Password: password
29
Welcome
<?php
session_start();
if (!isset($_SESSION['username'])) {
30
header("Location: login.php");
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Profile Page</title>
</head>
<body>
</body>
</html>
Profile
<?php
session_start();
$valid_username = "admin";
$valid_password = "password";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST['username'];
$password = $_POST['password'];
$_SESSION['username'] = $username;
header("Location: welcome.php");
31
exit();
} else {
echo "<script>alert('Invalid username or password.');</script>";
echo "<script>window.location.href='login.php';</script>";
}
} else {
header("Location: login.php");
exit();
}
?>
Login
<?php
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Login Form</title>
<style>
body {
font-family: Arial, sans-serif;
}
.container {
max-width: 300px;
margin: auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
}
.container input {
width: 100%;
padding: 10px;
margin: 10px 0;
}
32
.container button {
padding: 10px;
background-color: #5cb85c;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
.container button:hover {
background-color: #4cae4c;
}
</style>
</head>
<body>
<div class="container">
<h2>Login</h2>
<form action="profile.php" method="POST">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<button type="submit">Login</button>
</form>
</div>
</body>
</html>
Logout
<?php
session_start();
$_SESSION = array();
session_destroy();
33
header("Location: login.php");
exit();
?>
34
Practical-19
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<header>
<h2>Department of Engineering</h2>
<nav>
<ul>
<li><a href="#faculty">Faculty</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</nav>
</header>
<section id="about">
<h3>About Us</h3>
</section>
<section id="courses">
<h3>Courses Offered</h3>
<ul>
<li>BCA</li>
<li>BTech</li>
<li>MCA</li>
<li>MTech</li>
36
</ul>
</section>
<section id="faculty">
<ul>
<li>Professor A</li>
<li>Professor B</li>
<li>Professor C</li>
</ul>
</section>
<section id="contact">
<h3>Contact Us</h3>
<p>Email: [email protected]</p>
</section>
<footer>
<p>© <?php echo date("Y"); ?> PCTE Group Of Institues All rights
reserved.</p>
</footer>
37
</body>
</html>
38
Practical-20
<!DOCTYPE html>
<?php
$target_dir = $_POST["dirname"]."/";
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,
PATHINFO_EXTENSION));
$extensions = array("jpeg","jpg","png","pdf","gif");
if(isset($_POST["submit"])) {
if(!empty($_POST["dirname"])){
if(!is_dir($_POST["dirname"])) {
mkdir($_POST["dirname"]);
$uploadOk = 1;
39
else {
$uploadOk = 0;
exit;
$uploadOk = 1;
else {
$uploadOk = 0;
exit;
if (file_exists($target_file)) {
$uploadOk = 0;
exit;
40
}
$uploadOk = 0;
exit;
if ($uploadOk == 0)
else
if (move_uploaded_file($_FILES["fileToUpload"]
["tmp_name"], $target_file))
41
else
?>
</body>
</html>
42