0% found this document useful (0 votes)
58 views4 pages

Lab Session 9

This document provides instructions for a PHP lab session. It introduces PHP, describing what it is and some of its common uses. It then provides instructions for setting up PHP, Apache, and MySQL on a local system. The document includes examples of basic PHP syntax and functions. It concludes with tasks for students to complete, including displaying PHP info, using variables in HTML, writing PHP functions, and printing multiplication tables.

Uploaded by

Sohema anwar
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)
58 views4 pages

Lab Session 9

This document provides instructions for a PHP lab session. It introduces PHP, describing what it is and some of its common uses. It then provides instructions for setting up PHP, Apache, and MySQL on a local system. The document includes examples of basic PHP syntax and functions. It concludes with tasks for students to complete, including displaying PHP info, using variables in HTML, writing PHP functions, and printing multiplication tables.

Uploaded by

Sohema anwar
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/ 4

Web Engineering

Department of CS and SE

LAB SESSION 8: PHP

Objective
On completion of this lab, students will be able:

• To setup PHP on local systems.


• To understand basic syntax and concepts of PHP.

Introduction to PHP

PHP started out as a small open source project that evolved as more and more people found out how
useful it was. Rasmus Lerdorf unleashed the first version of PHP way back in 1994.PHP is a recursive
acronym for "PHP: Hypertext Preprocessor”. PHP is a server side scripting language that is embedded
in HTML. It is used to manage dynamic content, databases, session tracking, even build entire e-
commerce sites. It is integrated with a number of popular databases, including MySQL, PostgreSQL,
Oracle, Sybase, Informix, and Microsoft SQL Server.

PHP is pleasingly zippy in its execution, especially when compiled as an Apache module on the UNIX
side. The MySQL server, once started, executes even very complex queries with huge result sets in record
setting time.

PHP supports a large number of major protocols such as POP3, IMAP, and LDAP. PHP4 added support
for Java and distributed object architectures (COM and CORBA), making n-tier development a
possibility for the first time. PHP is forgiving: PHP language tries to be as forgiving as possible. PHP
Syntax is C-Like. Common uses of PHP.

PHP performs system functions, i.e. from files on a system it can create, open, read, write, and close
them. PHP can handle forms, i.e. gather data from files, save data to a file, through email you can send
data, return data to the user. You add, delete, and modify elements within your database through PHP.
Access cookies variables and set cookies. Using PHP, you can restrict users to access some pages of your
website. It can encrypt data.

Setup
In order to develop and run PHP Web pages three vital components need to be installed on your
computer system.
Web Server − PHP will work with virtually all Web Server software, including Microsoft's Internet
Information Server (IIS) but then most often used is freely available Apache Server. Download Apache
for free here − https://httpd.apache.org/download.cgi
Web Engineering
Department of CS and SE

Database − PHP will work with virtually all database software, including Oracle and Sybase but most
commonly used is freely available MySQL database. Download MySQL for free here −
https://www.mysql.com/downloads/
PHP Parser − In order to process PHP script instructions a parser must be installed to generate HTML
output that can be sent to the Web Browser. This tutorial will guide you how to install PHP parser on
your computer.

PHP Parser Installation


Before you proceed it is important to make sure that you have proper environment setup on your
machine to develop your web programs using PHP.
Type the following address into your browser's address box.
http://127.0.0.1/info.php
If this displays a page showing your PHP installation related information then it means you have PHP
and Webserver installed properly. Otherwise you have to follow given procedure to install PHP on
your computer.
Apache Configuration
If you are using Apache as a Web Server then this section will guide you to edit Apache Configuration
Files. PHP.INI File Configuration
The PHP configuration file, php.ini, is the final and most immediate way to affect PHP's functionality.

Example 1

<!DOCTYPE html>
<html>
<body>

<h1>My first PHP page</h1>

<?php
echo "Hello World!";
?>
</body>
</html>

Example 2

<! DOCTYPE html>


<html>
<body>
<?php
$color = "red";
echo "My car is " . $color. "<br>"; ?> </body> </html>
Web Engineering
Department of CS and SE

Creating (Declaring) PHP Variables

<?php
$txt = "Hello world!";
$x = 5;
$y = 10.5;
?>
<! DOCTYPE html>
<html>
<body>
<? Php
$txt = "W3Schools.com";
echo "I love " . $txt . "!";
?> </body>
</html>

The PHP echo Statement

<!DOCTYPE html>
<html>
<body>
<?php
echo "<h2>PHP is Fun!</h2>";
echo "Hello world!<br>";
echo "I'm about to learn PHP!<br>";
echo "This ", "string ", "was ", "made ", "with multiple parameters.";
?> </body>
</html>

PHP String
<?php
$x = "Hello world!";
$y = 'Hello world!'; echo $x;
echo "<br>";
echo $y;
?>
Web Engineering
Department of CS and SE

Lab Task
Note: Use proper naming conventions and also add comments.
1. Write a PHP script to get the PHP version and configuration information. (Hint: Use phpinfo()
)
2. $var = 'PHP Tutorial'. Put this variable into the title section and in the h3 tag
within an HTMLdocument and produce the following output.
Sample Output:
“PHP Tutorial PHP, an acronym for Hypertext Preprocessor, is a widely-used
open source general- purpose scripting language. It is a cross-platform, HTML
embedded server-side scripting language and is especially suited for web
development.”
3. Write a PHP function to test whether a number is greater than 30, 20 or 10 using
ternary operator.Take the number in a variable.

4. Write a script using one variable “$whatsit” to print the following to the browser
 Value is string.
 Value is double.
 Value is boolean.
 Value is integer. Value is NULL.
 (Hint: Use gettype() builtin function to get the type of variable).

5. Write a PHP program to swap values of two integer variables without using any third variable.
6. Write a PHP program to print out the multiplication table upto 5*5 Output:
 2345
 4 6 8 10
 6 9 12 15
 8 12 16 20
 10 15 20 25
 12 18 24 30

You might also like