Lecture 4 term 2
1 / 48

Lecture 4 Term 2 - PowerPoint PPT Presentation

  • Uploaded on

Lecture 4 Term 2. Introduction to PHP 30/1/12. Server Side Scripting. This is a web server technology in which a user's request is fulfilled by running a script directly on the web server to generate dynamic HTML pages.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about ' Lecture 4 Term 2' - dorjan

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Lecture 4 term 2

Lecture 4 Term 2

Introduction to PHP


Server side scripting
Server Side Scripting

  • This is a web server technology in which a user's request is fulfilled by running a script directly on the web server to generate dynamic HTML pages.

  • The primary advantage to server-side scripting is the ability to highly customize the response based on the user's requirements, access rights, or queries into data stores.

Ecommerce applications
Ecommerce Applications

  • E-Commerce applications exist since the 1960s.

  • Electronic Data Interchange (EDI)

  • Electronic Funds Transfer (EFT)

  • Termed Telecommunications Applications.


  • “….A set of computerised forms that automate common business processes such as purchase orders, invoices, shipping notices and requests for proposal”.

Problems with edi
Problems with EDI

  • Special software needed

  • Costly transaction and processing fees

  • Firms with several linked partners operating on different VANs often required different software and network connections.

Web based e business
Web Based E-Business

  • Internet

  • Intranet

  • Extranet

Technical challenges
Technical Challenges

  • Lack of systems security, reliability, standards and some communication protocol

  • Development tools are still evolving and changing rapidly

  • E.g. Difficult to integrate the Internet and EC software with some existing databases and applications

Static web applications
Static Web Applications

  • All information served to the clients browser is static. In other words the content for the page A served to client 1 is exactly the same as the content for page A served to client 2

  • The web server does not dynamically generate any part of the site’s content but simply serves static HMTL pages loaded from the Web Server’s file systems and sends them to the requesting client

Dynamic web applications
Dynamic Web-Applications

  • Initially, Common Gateway Interface Programming was used (CGI)

  • Server-side scripting allows us create dynamic and interactive web sites

  • PHP allows us create dynamic web sites

Serving a php file
Serving a PHP file

Internet – Connect to Web Browser


1. User enters web address to PHP file

2. Send Request for PHP file

3. Receive Request, find file and read it

URL: www.mypage.com/


Internet – Connect to Web Browser

7. Receive and interpret HTML file

4. Execute PHP statements

6. Return Results

  • Here are some fun

  • things to do:

  • Go shopping

  • Play soccer

5. Send back results

Introduction to php
Introduction to PHP

  • 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


  • The PHP syntax is very similar to Perl and C

  • PHP is often used together with Apache (web server) on various operating systems

  • It can also be used with Microsoft's IIS on Windows.

What is php
What is PHP?

  • PHP stands for PHP: Hypertext Preprocessor

  • PHP is a server-side scripting language, like ASP

  • PHP scripts are executed on the server

  • PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, Generic ODBC, etc.)

  • PHP is an open source software (OSS)

  • PHP is free to download and use

What is php1
What is PHP?

  • It is a server side scripting language designed for the web

  • PHP is embedded into HTML and is executed each time the web page is visited

  • PHP is interpreted by the web server and generates HTML code or other output for the user to see

More on php
More on PHP

  • PHP is an open source product.

  • You have access to the source code.

  • You can use it, alter it and redistribute it without charge.

  • PHP originally Personal Home Page, now stands for PHP hypertext preprocessor.

Advantages of php
Advantages of PHP

  • Performance

  • Database Integration

  • Built-in libraries

  • Cost

  • Portability

  • Source Code

Development environment
Development Environment

  • Server-side scripting - You need three things to make this work. The PHP parser (CGI or server module), a webserver and a web browser.

  • You need to run the webserver, with a connected PHP installation.

  • You can access the PHP program output with a web browser, viewing the PHP page through the server.

Programming php
Programming PHP

  • A typical PHP file includes:

    • HTML

    • PHP tags

    • PHP statements

    • Whitespace

    • Comments

  • Note

  • When you view the source of an PHP file on the client side you will not see the server side script, all you may view is the HTML generated.

Php tags
PHP Tags

  • <? echo “<p>Order Processed”;?>

  • This is the default tag used for PHP development

  • It follows the style of the SGML

Example 1
Example 1







echo "Hi, I'm a PHP script!";






<title>Create a variable</title>






$result= $a + $b;

echo $result;




Php statements
PHP Statements


echo "<p>Order Processed </p>";


  • The keyword echo prints the text Order Processed to the user’s browser.

    • Note: The semicolon at the end of the statement is mandatory, failure to include the semicolon will results in generating a syntax error.


  • Can improve code readability.

  • The addition of white space does not affect the execution of your code.

  • White space makes your PHP file bigger but makes the code more readable.


  • Comments act as essential documentation for a programmer’s code

  • Explains the purpose of the script

  • Who wrote it

  • Why they wrote it the way they did

  • The PHP interpreter will ignore the comments but it is important comments are included for updating and maintenance purposes

Creating comments
Creating Comments

  • Multilined Comment

    /* Author: Mary Brown

    Last Modified: 3/9/08


  • Single line Comments

    <?echo “<p> Order Processed </p>” ;?>// Start printing order


  • Variables in PHP are represented by a dollar sign followed by the name of the variable

  • The variable name is case-sensitive

  • A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores

Declaring a variable using php
Declaring a Variable Using PHP


$var = "Bob";

$Var = "Joe";

echo "$var, $Var"; // outputs "Bob, Joe"

$4site = 'not yet'; // invalid; starts with a number

$_4site = 'not yet'; // valid; starts with an underscore


Variable types
Variable Types

  • A variable type refers to the kind of data that is stored in it.

  • PHP data types include:

    • Integer

    • Double

    • String

    • Array

    • Object

Arithmetic operators
Arithmetic Operators

  • They are usually applied to integers or doubles if you apply an arithmetic operator to a string PHP will try and convert it to a number

  • If the string contains e or E it will be converted to a double otherwise it will be converted to int

String concatenation operator
String Concatenation/Operator

  • Used to add two strings together.

  • Syntax:


  • $qty1=12;

    echo $qty1. "Purchased<br/>"; ?>

  • To avoid having to write multiple echo commands use the (.)

Example 2
Example 2


$a="ebusiness ";

$b="is great";


echo $result;


Output: ebusiness is great

Control structures
Control Structures

  • Are structures within a programming language that allow us to control the flow of execution through a program or script.

  • The constructs that tell the programs to make decisions are known as conditional statements.

If statements
If Statements

  • If statements may be used to make a decision.

  • If the condition is true the following code block is executed.


    if ($a > $b)

    echo "a is bigger than b";


Else statements
Else Statements

  • This allows to provide an alternative action when the condition of the if statement is false.


    if ($a > $b)


    echo "a is bigger than b";




    echo "a is NOT bigger than b";



Elseif statements
elseif Statements


if ($a > $b)


echo"a is bigger than b";


elseif ($a == $b)


echo "a is equal to b";




echo "a is smaller than b";



Switch statements
Switch statements

  • The switch statement is similar to a series of IF statements on the same expression.

  • You may want to compare the same variable (or expression) with many different values, and execute a different piece of code depending on which value it equals to.


switch ($a)


case 0:

echo "a equals 0";


case 1:

echo "a equals 1";


case 2:

echo "a equals 2";



echo "a is not equal to 0, 1 or 2";



Iteration while loops
Iteration:While loops

  • It tells PHP to execute the nested statement(s) repeatedly, while the expression evaluates to true.

  • The value of the expression is checked each time at the beginning of the loop, so even if this value changes during the execution of the nested statement(s), execution will not stop until the end of the iteration.

  • If the while expression evaluates to false from the very beginning, the nested statement(s) won't even be run once.

While loops
While Loops


$i = 1;

while ($i <= 10)


echo $i++; /* the printed value would be

$i before the increment

(post-increment) */



For loops
For Loops

  • for (expr1; expr2; expr3) statement

  • The first expression (expr1) is evaluated once unconditionally at the beginning of the loop.

  • In the beginning of each iteration, expr2 is evaluated. If it evaluates to true, the loop continues and the nested statement(s) are executed. If it evaluates to false, the execution of the loop ends.

  • At the end of each iteration, expr3 is evaluated (executed).

For loops1
For Loops


for ($i = 1; $i <= 10; $i++)


echo $i;



Do while loops
Do…While Loops

  • do..while loops are very similar to while loops, except the truth expression is checked at the end of each iteration instead of in the beginning.

  • The main difference from regular while loops is that the first iteration of a do..while loop is guaranteed to run.

Do while loops1
Do..While Loops


$i = 0;



echo $i;


while ($i > 0);


Wamp server
Wamp Server

  • http://www.wampserver.com/en/

  • Windows web development environment

  • It allows you to create web applications with Apache, PHP and the MySQL database

  • It also comes with PHPMyAdmin and SQLiteManager to easily manage your databases

  • WampServer installs automatically and its usage is very intuitive

  • You will be able to tune your server without even touching the setting files