Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
64 views

Web App. Dev. Security - Lab Manual 5-2 - PHP-2

The document provides a laboratory manual for a course on secure web application development. It outlines 4 exercises for students to complete involving PHP basics. The exercises include: 1) calculating total cost from number of items and price, 2) calculating total marks from midterm and final exam weights, 3) calculating salary increase based on years of service, and 4) converting between Celsius and Fahrenheit temperatures. The lab objectives are to learn PHP syntax, variables, output statements, and operators.

Uploaded by

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

Web App. Dev. Security - Lab Manual 5-2 - PHP-2

The document provides a laboratory manual for a course on secure web application development. It outlines 4 exercises for students to complete involving PHP basics. The exercises include: 1) calculating total cost from number of items and price, 2) calculating total marks from midterm and final exam weights, 3) calculating salary increase based on years of service, and 4) converting between Celsius and Fahrenheit temperatures. The lab objectives are to learn PHP syntax, variables, output statements, and operators.

Uploaded by

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

ABU DHABI POLYTECHNIC

INFORMATION SECURITY ENGINEERING TECHNOLOGY

OCT 1- Secure Web Application Development Security

Laboratory Manual No. 5

PhP Basics and Introduction

Prepared By : Dua’a Abuhamdi


Lab Objectives:

After completing this lab exercises, the student will be able to:

 To describe the basic syntax of PhP Program


 To use variables in the program
 To create output statement
 To use PhP Operators in the program

Needed Materials:
 PC
 XAMPP (Apache)
 Notepad++

Course Outcomes:
 Describe how client-side and server-side programs enhance the functionality of the web site.
 Use language objects, functions and programming constructs to control the program flow

Using this link: http://www.w3schools.com/php/default.asp

Study the following topics:

 PHP Intro
 PHP Syntax
 PHP Variables
 PHP Echo
 PHP Operators
 PHP If..Else..Elseif
 PHP Switch

PHP Intro:

<?php
$x=10;
$myname = "Ahmad";
echo $myname . " is my name";
?>

Practice:

| Page 2
1. Write a PHP code that will manipulate two numbers. Compute and output the sum,
difference and the square of the first number.

<?php
$x=10;
$y=20;
$sum = $x + $y;
$diff = $x - $y;
$sq = $x * $x;
echo "The sum is " . $sum . "<br>";
echo "The difference is " . $diff . "<br>";
echo "The square of the first number is " . $sq;
?>

2. Write PHP code that will manipulate any temperature in Celsius. Then, print its
equivalent Fahrenheit temperature.

F = C * 1.8 + 32
PHP If else

<?php
$average = (70+90+70+80)/4;
if ($average > 70)
echo "Good Job";
else
echo "Study harder";

echo $average > 70 ? "Good Job" : "Study Harder";

PHP Switch

<?php
$favcolor="red";

switch ($favcolor) {
  case "red":
    echo "Your favorite color is red!";
    break;
  case "blue":
    echo "Your favorite color is blue!";
    break;
  case "green":
    echo "Your favorite color is green!";
    break;
  default:
    echo "Your favorite color is neither red, blue, or green!";

| Page 3
}
?>

Laboratory Exercise:

1. Write a PHP code that will manipulate the number of pieces and the amount of an item
purchased by the customer. Assume any value of your choice. Compute and output the Total
Cost.

Example:
The number of pieces:
The amount of an item:
The total cost:

<?php
$P = $_POST['pieces'];
$I = $_POST['item'];
?>

<!DOCTYPE html>
<html>
<head>
<title>Task1</title>
</head>
<body>
<fieldset>
<legend>
Enter Your Purchasing Info
</legend>

| Page 4
<form action="task1.php" method="POST">
The number of pieces: <input type="number" name="pieces"><br>
The amount of an item: <input type="number" name="item"><br><br>
<input type="submit" name="submit"><br>
</form>

<?php
echo "The number of pieces:".$P."<br>";
echo "The amount of an item:".$I."<br>";
echo "The total cost:".($P*$I)."<br>";
?>
</fieldset>
</body>
</html>

2. Write a PHP code that will manipulate Midterm and Final Mark. Assume any value of your
choice. Compute and output the Total Marks by adding the 40% of Midterm and 60% of Final
Marks.

<?php
$M = $_POST['mid'];
$F = $_POST['final'];
$Total = ($M*0.4)+($F*0.6);
?>

<!DOCTYPE html>
<html>
<head>
<title>Task2</title>
</head>
<body>
<fieldset>
<legend>
Enter Your Marks Info
</legend>
<form action="task2.php" method="POST">

| Page 5
Your MidTerm Mark: <input type="number" name="mid"><br>
Your Final Mark: <input type="number" name="final"><br><br>
<input type="submit" name="submit"><br>
</form>

<?php
echo "Your MidTerm Mark: ".$M."<br>";
echo "Your Final Mark: ".$F."<br>";
echo "Your Total Mark is: ".$Total."<br>";
?>
</fieldset>
</body>
</html>

3. ABC Company decided to increase the salary of their employees based on the number of years
in service. Write a PHP code that will assume the current salary of an employee. Compute and
output the new salary from the increased given by the company.

Number of Years in Service Percent of increase from employee’s current salary

More than 10 years 30 percent


5 years to 10 years 20 percent
Less than 5 years 10 percent

<?php
$Y = $_POST['years'];
$S = $_POST['salary'];

if ($Y > 10) {


echo "Your increased salary is: " .$S*0.3+$S.
}
elseif ($Y >=5 and <=10) {
echo "Your increased salary is: ".$S*0.2+$S.
}
else {
echo "Your increased salary is: ".$S*0.1+$S.
}

?>
<!DOCTYPE html>
<html>
<head>
<title>Task3</title>
</head>
<body>

| Page 6
<fieldset>
<legend>
Enter Your Info
</legend>
<form action="task1.php" method="POST">
Enter your salary: <input type="number" name="salary"><br>
Enter the amount of years: <input type="number" name="years"><br><br>
<input type="submit" name="submit"><br>
</form>
</fieldset>
</body>
</html>

3. Write PHP code that will manipulate any temperature in Celsius. Then, print its
equivalent Fahrenheit temperature.

F = C * 1.8 + 32

<!DOCTYPE html>
<html>
<head>
<title>Task4</title>
</head>
<body>

<form action="task4.php" method="POST">


<table border="1">
<tr>
<td>Fehrenheit</td>
<td><input type="number" name="Fehrenheit"></td>
<td><button type="submit">Convert to Celsius</button></td>

</tr>
<tr>
<td> Celsius </td>
<td><input type="number" name="Celsius"></td>

<td><button type="submit">Convert to Fehrenheit</button></td>

| Page 7
</tr>

</table>

<?php
$Feh = $_POST['Fehrenheit'];
$Cel = $_POST['Celsius'];

$F = ((float)$Cel * 1.8) + 32;


$C = ((float)$Feh - 32) / 1.8;

echo "From C to F" . $F . "<br>";


echo "From F to C". $C;

?>
</form>

</body>
</html>

| Page 8

You might also like