0% found this document useful (0 votes)
48 views27 pages

ADIP Chapter 1

The document provides an introduction to server-side programming with PHP. It discusses setting up the PHP environment with XAMPP, writing basic PHP code, using variables, operators, and control statements in PHP programs. The document is intended to teach beginners the fundamentals of PHP programming.

Uploaded by

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

ADIP Chapter 1

The document provides an introduction to server-side programming with PHP. It discusses setting up the PHP environment with XAMPP, writing basic PHP code, using variables, operators, and control statements in PHP programs. The document is intended to teach beginners the fundamentals of PHP programming.

Uploaded by

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

COLLEGE OF COMPUTING AND INFORMATICS

Department of Information Technology

Advanced Internet Programming


(ITec3092)
October, 2017
Prepared by Yimer A. Assosa, Ethiopia
Chapter 1: Introduction
• Introduction to Server-side programming
• Basics of PHP
• Setting up your environment
• Elements of php
– Syntax
– Variables
– Comments (// and /* */)
– Conditional statements
– Looping statments
Introduction
• Server-side scripting is a technique used in web development
– which involves employing scripts on a web server
– which produce a response customized for each user's (client's)
request to the website.
– Scripts can be written in any of a number of server-side
scripting languages that are available
– PHP, Active Server Pages (ASP), Java Servlets, Java Server
Pages (JSPs), Perl, Ruby
. . . Introduction
• PHP is the Web development language written
– by Web developers
– for Web developers
• PHP stands for PHP: Hypertext Preprocessor.
• The product was originally named
– Personal Home Page tools
• PHP is a server-side scripting language,
– which can be embedded in HTML or used as a standalone ph.JPG
• Client-side scripting
– the desirable, eye-catching part of Web development.
• In contrast, server-side scripting
– invisible to the user.
. . . Introduction
• Server-side Web scripting is mostly about connecting Web sites
to back end servers, such as databases.
• This enables the following types of two-way communication:
– Server to client: Web pages can be assembled from back end-server
output.
– Client to server: Customer-entered information can be acted upon.
– client-server architecture (php).JPG
PHP: Basics
• PHP is a powerful server-side scripting language for creating dynamic and
interactive websites.
• PHP is the widely-used, free, and efficient alternative to competitors such as
Microsoft's ASP.
• PHP is perfectly suited for Web development and can be embedded directly
into the HTML code.
• PHP is often used together with Apache (web server) on various operating
systems
• PHP scripts are executed on the server
• PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid,
PostgreSQL, Generic ODBC, etc.)
• PHP is an open source software (OSS)
• PHP is free to download and use
What is A PHP File?

• PHP files may contain text, HTML tags and scripts


• PHP files are returned to the browser as plain HTML
• PHP files have a file extension of ".php"
Why PHP?
• PHP runs on different platforms (Windows, Linux, Unix, etc.)
• PHP is compatible with almost all servers used today (Apache, IIS, etc.)
• PHP is FREE to download (from apache friends)
• PHP is easy to learn and runs efficiently on the server side
PHP can do a lot of tasks (advantages)
• PHP can
– generate dynamic page content
– create, open, read, write, delete, and close files on the server
– collect form data
– send and receive cookies
– add, delete, modify data in your database
– be used to control user-access
– encrypt data
PHP drawbacks (Disadvantages)
• Security: Since it is open sourced, so all people can see the source code, if there
are bugs in the source code, it can be used by people to explore its weakness
• In order for anything to update on the page a request for a new page must be
sent to the server (e.g. by clicking a link or submitting a form)
• You have to run a server or your code will not run
• Not really PHP’s fault, but you still have to contend with designing for multiple
browsers
• The Object Oriented support in PHP is relatively new and some people don’t
like it
Where To Start?
• Install an Apache server on a Windows or Linux machine l be
l
wi lling
• Install PHP on a Windows or Linux machine u re sta
at in
• Install MySQL on a Windows or Linux machine i
e
s f d by P P
h
ll t sse M
A cce
a X A
PHP - Syntax
Syntax - The rules that must be followed to write properly
<?php
structured code
$year=2;
$Syear=“Two”
echo $Syear+$year+“times”;
?>
How to Install XAMPP To Start Php Programs
• You can download XAMPP from https://www.appachefriend.org/
Installing XAMPP
Installing XAMPP
• You must remember the folder that your xampp is available because later, you will access any
files from this folder.
• After that finish the installation by clicking on Next until the installation is complete.
Using XAMPP Control Panel
• Open XAMPP control panel Start MySql database server, apache web server . . . . . .
Check The Start of Apache and MySql
1. Open your browser write localhost on the URL and click enter
2. Sometimes, when you start apache(listens port 80) port 80 may be used by other process, at
this time you can change the port# by clicking on config in front of apace in the xampp
control panel and change the port# to 8080 and save it
3. Then write localhost:8080 and click enter
WRITE YOUR FIRST PHP FILE
• To test whether it really running or not,
1. go to your folder that you installed XAMPP (C:/xampp)
2. Click on htdocs (which is important folder)
3. Create a folder called IP
4. Create and run your first php file (.php extension)
To open your php file
5. Open your favourite browser
6. Write localhost/name of your folder

7. i.e. localhost/IP and click enter


8. It displays the content that you include in the file
Write Your First Php File
what you should have understood so far
• When you want to work on PHP code you need to start
Apache/MySQL on the XAMPP control panel
• Save all of your PHP documents into the htdocs folder with the file
extension .php
• PHP files can be inside subfolders of htdocs
• Run your PHP file by browsing to http://localhost/foldername
• The default page (home page) of each folder is index.php
• If you want to view a page with a different name, open
http://localhost/foldername/pagename.php
PHP Syntax
• <html>
<head>
The syntax <title>Using PHP</title>
</head>
<body>

<?php <?php
echo “Welcome to Today’s tutorial!";
?>
</body>
Welcome to Today’s tutorial!
</html>

?> • Note: the PHP function echo is a means of outputting


text to the web browser.
Careful when echoing quotes!

• Don't use quotes inside your string


• Escape your quotes that are within the string with a slash. To escape a quote
just place a slash directly before the quotation mark, i.e. \“
• Use single quotes (apostrophes) for quotes inside your string

<?php
// This won't work because of the quotes around left!
echo "<h5 id=“left">I love using PHP!</h5>";
// OK because we escaped the quotes!
echo "<h5 class=\“left\">I love using PHP!</h5>";
// OK because we used an apostrophe '
echo "<h5 class=‘left'>I love using PHP!</h5>";
?>
Php Variables
A variable is a means of storing a value, such as text string “Second
year!" or the integer value 2. A variable can then be reused
throughout your code <?php
$my_string = “Welcome to today’s
Declaration syntax tutorial!";
$my_number = 2;
$variable_name = Value; $my_letter = s;
echo $my_string;
echo $my_number;
Echoing Variables echo $my_letter . “second year IT
student”;
 Echoing Variables and Text Strings echo ” second year IT student” .
 Using string concatenation operator (.)
$my_letter;
?>
PHP – Operators

• In all programming languages, operators are used to manipulate or


perform operations on variables and values
There are many operators used in PHP, so we have separated them
into the following categories to make it easier to learn them all.
Assignment Operators (=)
 Arithmetic Operators (+, -, /, *, %)
Comparison Operators (==, !=, >, >=, <, <=)
String Operators (.)
Combination Arithmetic & Assignment Operators
(+=, -=, *=, /=, %=, .=)
(You already familiar in another programming language )
Php Control Statements
• Control statements are the same as any other programming language
• Php if statements $month=“May”; Case “July”:
Case “June”: echo “Summer”;
– If $month=0;
echo “Class end!”; break;
If($month==4) echo “April”;
– If else break; Default:
Else echo “Unknown
– Else if Case “May”: echo “Unknown
Month”;
echo “Current Month”;
– Nested if Month!”; break;
break;

• Php switch statements


– Case: it takes a single variable as input and then checks it against all the different cases you set
up for that switch statement (e.g. case May: Output: Current Month!)
– Break (to stop executing all the cases that follow the correct case)
– Default case (when the variable doesn’t match all conditions, no case before default default:)
Loop
• Often when you write code, you want the same block of code to run
over and over again in a row.
• Instead of adding several almost equal code-lines in a script, we can
use loops to perform a task like this.
• In PHP, we have the following looping statements:
– while - loops through a block of code as long as the specified condition
is true
– do...while - loops through a block of code once, and then repeats
the loop as long as the specified condition is true
– for - loops through a block of code a specified number of times
– foreach - loops through a block of code for each element in an
array
<?php
Syntax $x = 1;

while($x <= 5) {
while (condition is true) { echo "The number is: $x <br>";
$x++;
code to be executed; }
} ?>

<?php
$x = 1;
do {
code to be executed; do {
echo "The number is: $x <br>";
} while (condition is true); $x++;
} while ($x <= 5);
?>

<?php
for (init counter; test counter; increment counter) {
for ($x = 0; $x <= 10; $x++) {
code to be executed; echo "The number is: $x <br>";
} }
?>
More examples on PHP

……..Practice!!
Thank You ...

27

You might also like