SlideShare a Scribd company logo
2
Most read
3
Most read
8
Most read
Chapter One:
Server Side
Scripting Basics
11/28/2019
BantamlakDejene,Information
Technology
1
Introduction to Server-Side Scripting
Today’s Web users expect exciting pages that are updated
frequently and provide a customized experience. For them, Web
sites are more like communities, to which they’ll return time
and again. At the same time, Web-site administrators want sites
that are easier to update and maintain, understanding that’s the
only reasonable way to keep up with visitors’ expectations. For
these reasons and more, PHP and MySQL have become the de
facto standards for creating dynamic, database driven Web sites.
11/28/2019
BantamlakDejene,Information
Technology
2
Cont.….
Dynamic Web sites are flexible and potent creatures, more accurately
described as applications than merely sites. Dynamic Web sites
Respond to different parameters (for example, the time of day or the
version of the visitor’s Web browser)
Have a “memory,” allowing for user registration and login, e-commerce,
and similar processes
Almost always integrate HTML forms, allowing visitors to perform
searches, provide feedback, and so forth
Often have interfaces where administrators can manage the site’s content
Are easier to maintain, upgrade, and build upon than statically made sites.
11/28/2019
BantamlakDejene,Information
Technology
3
Cont.….
There are many technologies available for creating dynamic
Web sites. The most common are ASP.NET (Active Server
Pages, a Microsoft construct), JSP (Java Server Pages),
ColdFusion, Ruby on Rails (a Web development framework
for the Ruby programming language), and PHP. Dynamic
Web sites don’t always rely on a database, but more and
more of them do, particularly as excellent database
applications like MySQL are available at little to no cost.
11/28/2019
BantamlakDejene,Information
Technology
4
Server-Side Scripting Languages
PHP originally stood for “Personal Home Page” as it was created in 1994 by Rasmus
Lerdorf to track the visitors to his online résumé. As its usefulness and capabilities
grew, it came to mean “PHP: Hypertext Preprocessor. According to the official PHP
Web site, found at www.php.net A, PHP is a “widely used general-purpose scripting
language that is especially suited for Web development and can be embedded into
HTML.” It’s a long but descriptive definition.
Server side refers to the fact that everything PHP does occurs on the server. A Web
server application, like Apache or Microsoft’s IIS, is required and all PHP scripts
must be accessed through a URL. Its cross-platform nature means that PHP runs on
most operating systems, including Windows, UNIX, and Macintosh. More important,
the PHP scripts written on one server will normally work on another with little or no
modification.
11/28/2019
BantamlakDejene,Information
Technology
5
Cont.….
MySQL (www.mysql.com) is the world’s most popular open-source database. In
fact, today MySQL is a viable competitor to the pricey goliaths such as Oracle and
Microsoft’s SQL Server. Like PHP, MySQL offers excellent performance,
portability, and reliability, with a moderate learning curve and little to no cost.
MySQL is an RDBMS. A database, in the simplest terms, is a collection of data, be
it text, numbers, or binary files, stored and kept organized by the DBMS.
MySQL is an open-source application, like PHP, meaning that it is free to use or
even modify. There are occasions in which you should pay for a MySQL license,
especially if you are making money from the sales or incorporation of the MySQL
product. The MySQL software consists of several pieces, including the MySQL
server, the MySQL client, and numerous utilities for maintenance and other
purposes. PHP always had good support for MySQL, and that is even truer in the
most recent versions of the language.
11/28/2019
BantamlakDejene,Information
Technology
6
Use Basic Syntax
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Page Title</title></head>
<body><!-- Example 1 - template.html -->
</body></html>
11/28/2019
BantamlakDejene,Information
Technology
7
Cont.….
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Basic PHP Page</title></head>
<body><!—Example 2 - first.php -->
<p>This is standard HTML.</p><?php?></body></html>
11/28/2019
BantamlakDejene,Information
Technology
8
Send Data to Web Browser
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"
/>
<title>Using Echo</title></head>
<body><!-- Example 3 - second.php -->
<p>This is standard HTML.</p>
<?php
echo <p>This is generated by using PHP!</p>
?></body></html>
11/28/2019
BantamlakDejene,Information
Technology
9
Write Comments
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Comments</title></head>
<body><?php
# Example 4 - comments.php
# Created March 16, 2011
# Created by Larry E. Ullman
# This script does nothing much.
echo '<p>This is a line of text.<br />
This is another line of text.</p>';
/*
echo 'This line will not be executed.';
*/
echo "<p>Now I'm done.</p>";
// End of PHP code.
?></body></html>
11/28/2019
BantamlakDejene,Information
Technology
10
Utilize Variables
Regardless of what type you are creating, all variable names in
PHP follow certain syntactical rules:
A variable’s name must start with a dollar sign ($), for example, $name.
The variable’s name can contain a combination of letters, numbers, and
the underscore, for example, $my_report1.
The first character after the dollar sign must be either a letter or an
underscore (it cannot be a number).
Variable names in PHP are case sensitive! This is a very important rule. It
means that $name and $Name are entirely different variables.
11/28/2019
BantamlakDejene,Information
Technology
11
Cont.….
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN“
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Predefined Variables</title></head>
<body><?php # Example 5 - predefined.php
// Create a shorthand version of the variable names:
$file = $_SERVER['SCRIPT_FILENAME'];
$user = $_SERVER['HTTP_USER_AGENT'];
$server = $_SERVER['SERVER_SOFTWARE'];
// Print the name of this script:
echo "<p>You are running the file:<br /><b>$file</b>.</p>n";
// Print the user's information:
echo "<p>You are viewing this page using:<br /><b>$user</b></p>n";
// Print the server's information:
echo "<p>This server is running: <br /><b>$server</b>.</p>n";
?></body></html>
11/28/2019
BantamlakDejene,Information
Technology
12
Manipulate Strings
A string is merely a quoted chunk of characters: letters, numbers, spaces, punctuation, and so
forth. These are all strings:
-> ‘Tobias’ -> “In watermelon sugar” -> ‘100’ -> ‘August 2, 2011
Make a string variable, assign a string value to a valid variable name:
$first_name = 'Tobias'; $today = 'August 2, 2011';
When creating strings, you can use either single or double quotation marks to encapsulate the characters,
just as you would when printing text. Likewise, you must use the same type of quotation mark for the
beginning and the end of the string. If that same mark appears within the string, it must be escaped: $var =
"Define "platitude", please."; Or you can also use the other quotation mark type: $var = 'Define
"platitude", please.';
To print out the value of a string, use either
echo or print:
echo $first_name
To print the value of string within a context, you must use double quotation marks:
echo "Hello, $first_name";
11/28/2019
BantamlakDejene,Information
Technology
13
Cont.….
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Strings</title></head>
<body><?php # Example6 - strings.php
// Create the variables:
$first_name = 'ሐዲስ';
$last_name = 'አለማሁ';
$book = 'ፍቅር እስከ መቃብር';
// Print the values:
echo "<p>The book <em>$book</em> was written by $first_name $last_name.</p>";
?></body></html>
11/28/2019
BantamlakDejene,Information
Technology
14
Cont.….
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Strings</title></head>
<body><?php # string concatenation, length and word counting =>
string_concat.php
// Create the variables:
$favoriteAnimal = 'cat';
$myArray ['age']= '28';
$about = "My age";
$len = strlen($about);
$word = str_word_count("My favorite animals are {$favoriteAnimal}s");
// Print the values:
echo "My favorite animals are {$favoriteAnimal}s => There are {$word} words in
this sentence</br>"; // using curly bracket
echo $about . " is " . $myArray["age"] . "</br>"; // using . operator
echo "The length of " . $about . " is " . $len;
?></body></html>
11/28/2019
BantamlakDejene,Information
Technology
15
Cont.….
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Strings</title></head>
<body><?php # string search and count => string_search.php
// Create the variables:
$su = 'Welcome to Samara University. Welcome to Department of Information Technology <br>
This is the Department of Information Technology from College of Engineering and Technology in Samara University';
$search = strstr($su, "Engineering");// searches the string from the sentence
$searchF = strpos($su, "University");// locates the string starting from beginning
$searchE = strrpos($su, "Samara");// locates the string starting from end
$count = substr_count($su, "Technology");//counts the repetition of the string in the text
$countS = substr_count($su, "to", 9);//counts the repetition of the string in the text starting form the given index
$countF = substr_count($su, "of", 45, 100);//counts the repetition of the string in the text between the indexes
// Print the values:
echo $su . "</br>";
echo "</br>Engineering is found at => ". $search . "</br>";
echo "University is found at => " . $searchF . " => from the beginning </br>";
echo "Samara is found at => " . $searchE . " => from the end </br>";
echo "Technology is repeated => " . $count . " => times in the text </br>";
echo "to is repeated => " . $countS . " => times in the text starting from index 9 </br>";
echo "of is repeated => " . $countF . " => times in the text between index 45 and 100 </br>";
?></body></html>
11/28/2019
BantamlakDejene,Information
Technology
16
Cont.….
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Strings</title></head>
<body><?php # string manipulation => string_manipulation.php
// Create the variables:
$myString = "It was the best of times, it was the worst of times";
$string = "Here's a little string";
$str = "Information Technology";
echo $myString . "</br></br>";
echo str_replace("times", "bananas", $myString, $num ). "</br>";//replaces all and count it
echo "The text was replaced $num times. </br></br>";
echo substr_replace($myString, "bananas", 11 ). "</br></br>";//replaces from the given index
echo substr_replace($myString, "bananas", 19, 5). "</br></br>";//replaces from the given index to the given number of characters
echo substr_replace($myString, "really", 3, 0) . "</br></br>";
echo strtr($myString, " '", "+-"). "</br></br>";
echo strtolower($str) . "</br></br>";
echo ucfirst($str) . "</br></br>";
echo lcfirst($str) . "</br></br>";
?></body></html>
11/28/2019
BantamlakDejene,Information
Technology
17
Cont.….
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><title>Type Specifiers in Action</title >
<link rel="stylesheet" type="text/css" href="common.css"></head>
<body><h1>Type Specifiers in Action</h1>
<?php
$myNumber = 123.45;
printf("Binary: %b </br>", $myNumber);
printf("Character: %c </br>", $myNumber);
printf("Decimal: %d </br>", $myNumber);
printf("Scientific: %e </br>", $myNumber);
printf("Float: %f </br>", $myNumber );
printf("Octal: %o </br>", $myNumber );
printf("String: %s </br>", $myNumber );
printf("Hex (lower case): %x </br>", $myNumber );
printf("Hex (upper case): %X </br>", $myNumber );
?></body></html>
11/28/2019
BantamlakDejene,Information
Technology
18
Manipulate Numbers Work with Constants
PHP has both integer and floating-point (decimal) number types. These two types can be
classified under the generic title numbers without losing any valuable distinction (for the most
part). Valid number-type variables in PHP can be anything like
-> 8 -> 3.14 -> 10980843985 -> -4.2398508 -> 4.4e2
Notice that these values are never quoted—quoted numbers are strings with neither numeric
values— nor do they include commas to indicate thousands. Also, a number is assumed to be
positive unless it is preceded by the minus sign (-). Along with the standard arithmetic
operators
you can use on numbers (Table 1.1), there are dozens of functions built into PHP. Two
common ones are round( ) and number_format( ). The former rounds a decimal to the
nearest integer:
$n = 3.14;
$n = round ($n); // 3
11/28/2019
BantamlakDejene,Information
Technology
19
Cont.….
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Numbers</title></head><body>
<?php # Script 1.8 - numbers.php
// Set the variables:
$quantity = 30; // Buying 30 widgets.
$price = 119.95;
$taxrate = .05; // 5% sales tax.
// Calculate the total:
$total = $quantity * $price;
$total = $total + ($total * $taxrate);
// Calculate and add the tax.
// Format the total:
$total = number_format ($total, 2);
// Print the results:
echo "<p/>You are purchasing </br>" . $quantity . "</br> widget(s) at a cost of <br>$" . $price .
"</br> each. With tax, the total comes to <b>$" . $total . ".</br></p>";
?></body></html>
11/28/2019
BantamlakDejene,Information
Technology
20
Cont.….
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Constants</title></head><body>
<?php # Script 1.9 - constants.php
// Set today's date as a constant:
define ('TODAY', 'March 16, 2011');
// Print a message, using predefined constants and the TODAY constant:
echo '<p>Today is ' . TODAY . '.</br> This server is running version <b>' . PHP_VERSION .
'</b>
of PHP on the <b>' . PHP_OS . '</b> operating system.</p>';
?></body></html>
11/28/2019
BantamlakDejene,Information
Technology
21
THANK YOU
11/28/2019
BantamlakDejene,Information
Technology
22
Ad

Recommended

PPTX
Php ch-2_html_forms_and_server_side_scripting
bantamlak dejene
 
PPTX
Php ch-1_server_side_scripting_basics
bantamlak dejene
 
PDF
phptutorial
tutorialsruby
 
PDF
Programming with php
salissal
 
PDF
xhtml-documentation
tutorialsruby
 
PPT
Open Source Package Php Mysql 1228203701094763 9
isadorta
 
PPT
Introduction to XML
Jussi Pohjolainen
 
DOCX
Unit 2.2
Abhishek Kesharwani
 
PPT
C5 Javascript
Vlad Posea
 
PPT
PHP MySQL
Md. Sirajus Salayhin
 
DOC
PHP form tutorial
Promb
 
PPT
Lecture7 form processing by okello erick
okelloerick
 
PDF
Unit 1 php_basics
Kumar
 
PPTX
IPW HTML course
Vlad Posea
 
PPT
uptu web technology unit 2 Xml2
Abhishek Kesharwani
 
PPTX
What should or not be programmed on the web
Mohammad Kamrul Hasan
 
PPTX
Xml ppt
seemadav1
 
PPTX
Web programming xml
Uma mohan
 
PDF
Web programming by Najeeb ullahAzad(1)
azadmcs
 
PDF
Introduction to XHTML
Hend Al-Khalifa
 
PPTX
Web Application Development using PHP Chapter 1
Mohd Harris Ahmad Jaal
 
PDF
Introduction to php
KIRAN KUMAR SILIVERI
 
PPT
php 1
tumetr1
 
PPT
Php1
mohamed yusuf
 
PPTX
Php by shivitomer
Shivi Tomer
 
PPT
Php training100%placement-in-mumbai
vibrantuser
 
PDF
PHP Basics
Roohul Amin
 
PPTX
Ch1(introduction to php)
Chhom Karath
 

More Related Content

What's hot (14)

DOCX
Unit 2.2
Abhishek Kesharwani
 
PPT
C5 Javascript
Vlad Posea
 
PPT
PHP MySQL
Md. Sirajus Salayhin
 
DOC
PHP form tutorial
Promb
 
PPT
Lecture7 form processing by okello erick
okelloerick
 
PDF
Unit 1 php_basics
Kumar
 
PPTX
IPW HTML course
Vlad Posea
 
PPT
uptu web technology unit 2 Xml2
Abhishek Kesharwani
 
PPTX
What should or not be programmed on the web
Mohammad Kamrul Hasan
 
PPTX
Xml ppt
seemadav1
 
PPTX
Web programming xml
Uma mohan
 
PDF
Web programming by Najeeb ullahAzad(1)
azadmcs
 
PDF
Introduction to XHTML
Hend Al-Khalifa
 
C5 Javascript
Vlad Posea
 
PHP form tutorial
Promb
 
Lecture7 form processing by okello erick
okelloerick
 
Unit 1 php_basics
Kumar
 
IPW HTML course
Vlad Posea
 
uptu web technology unit 2 Xml2
Abhishek Kesharwani
 
What should or not be programmed on the web
Mohammad Kamrul Hasan
 
Xml ppt
seemadav1
 
Web programming xml
Uma mohan
 
Web programming by Najeeb ullahAzad(1)
azadmcs
 
Introduction to XHTML
Hend Al-Khalifa
 

Similar to server side scripting basics (20)

PPTX
Web Application Development using PHP Chapter 1
Mohd Harris Ahmad Jaal
 
PDF
Introduction to php
KIRAN KUMAR SILIVERI
 
PPT
php 1
tumetr1
 
PPT
Php1
mohamed yusuf
 
PPTX
Php by shivitomer
Shivi Tomer
 
PPT
Php training100%placement-in-mumbai
vibrantuser
 
PDF
PHP Basics
Roohul Amin
 
PPTX
Ch1(introduction to php)
Chhom Karath
 
PDF
WT_PHP_PART1.pdf
HambardeAtharva
 
PPTX
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
DRambabu3
 
PPT
PHP MySQL Workshop - facehook
Shashank Skills Academy
 
PPT
PHP
sometech
 
PPT
PHP - Introduction to PHP Fundamentals
Vibrant Technologies & Computers
 
PPT
PHP and MySQL
bmani
 
PPTX
FYBSC IT Web Programming Unit IV PHP and MySQL
Arti Parab Academics
 
PDF
Web Design & Development - Session 7
Shahrzad Peyman
 
PPT
Php
zalatarunk
 
PPTX
php Chapter 1.pptx
HambaAbebe2
 
PPTX
Php unit i
BagavathiLakshmi
 
PPTX
Server – side Technologies PHP for web dev.pptx
MarioCaday2
 
Web Application Development using PHP Chapter 1
Mohd Harris Ahmad Jaal
 
Introduction to php
KIRAN KUMAR SILIVERI
 
php 1
tumetr1
 
Php by shivitomer
Shivi Tomer
 
Php training100%placement-in-mumbai
vibrantuser
 
PHP Basics
Roohul Amin
 
Ch1(introduction to php)
Chhom Karath
 
WT_PHP_PART1.pdf
HambardeAtharva
 
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
DRambabu3
 
PHP MySQL Workshop - facehook
Shashank Skills Academy
 
PHP - Introduction to PHP Fundamentals
Vibrant Technologies & Computers
 
PHP and MySQL
bmani
 
FYBSC IT Web Programming Unit IV PHP and MySQL
Arti Parab Academics
 
Web Design & Development - Session 7
Shahrzad Peyman
 
php Chapter 1.pptx
HambaAbebe2
 
Php unit i
BagavathiLakshmi
 
Server – side Technologies PHP for web dev.pptx
MarioCaday2
 
Ad

More from bantamlak dejene (8)

PPTX
object oriented fundamentals in vb.net
bantamlak dejene
 
PPTX
introduction to .net
bantamlak dejene
 
PPTX
introduction to vb.net
bantamlak dejene
 
PPTX
html forms and server side scripting
bantamlak dejene
 
PPTX
server side scripting basics by Bantamlak Dejene
bantamlak dejene
 
PPTX
Vb ch 3-object-oriented_fundamentals_in_vb.net
bantamlak dejene
 
PPTX
Vb ch 2-introduction_to_.net
bantamlak dejene
 
PPTX
Vb ch 1-introduction
bantamlak dejene
 
object oriented fundamentals in vb.net
bantamlak dejene
 
introduction to .net
bantamlak dejene
 
introduction to vb.net
bantamlak dejene
 
html forms and server side scripting
bantamlak dejene
 
server side scripting basics by Bantamlak Dejene
bantamlak dejene
 
Vb ch 3-object-oriented_fundamentals_in_vb.net
bantamlak dejene
 
Vb ch 2-introduction_to_.net
bantamlak dejene
 
Vb ch 1-introduction
bantamlak dejene
 
Ad

Recently uploaded (20)

PDF
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
PDF
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
PDF
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
PDF
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
PDF
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
PDF
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
 
PPTX
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
PPTX
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
PDF
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
Malinda Kapuruge
 
PDF
Unlocking FME Flow’s Potential: Architecture Design for Modern Enterprises
Safe Software
 
PDF
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 
PPTX
Practical Applications of AI in Local Government
OnBoard
 
PPSX
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
PPTX
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
PPTX
reInforce 2025 Lightning Talk - Scott Francis.pptx
ScottFrancis51
 
PDF
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
PPTX
𝙳𝚘𝚠𝚗𝚕𝚘𝚊𝚍—Wondershare Filmora Crack 14.0.7 + Key Download 2025
sebastian aliya
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
PDF
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
PDF
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
 
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
Malinda Kapuruge
 
Unlocking FME Flow’s Potential: Architecture Design for Modern Enterprises
Safe Software
 
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 
Practical Applications of AI in Local Government
OnBoard
 
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
reInforce 2025 Lightning Talk - Scott Francis.pptx
ScottFrancis51
 
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
𝙳𝚘𝚠𝚗𝚕𝚘𝚊𝚍—Wondershare Filmora Crack 14.0.7 + Key Download 2025
sebastian aliya
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 

server side scripting basics

  • 1. Chapter One: Server Side Scripting Basics 11/28/2019 BantamlakDejene,Information Technology 1
  • 2. Introduction to Server-Side Scripting Today’s Web users expect exciting pages that are updated frequently and provide a customized experience. For them, Web sites are more like communities, to which they’ll return time and again. At the same time, Web-site administrators want sites that are easier to update and maintain, understanding that’s the only reasonable way to keep up with visitors’ expectations. For these reasons and more, PHP and MySQL have become the de facto standards for creating dynamic, database driven Web sites. 11/28/2019 BantamlakDejene,Information Technology 2
  • 3. Cont.…. Dynamic Web sites are flexible and potent creatures, more accurately described as applications than merely sites. Dynamic Web sites Respond to different parameters (for example, the time of day or the version of the visitor’s Web browser) Have a “memory,” allowing for user registration and login, e-commerce, and similar processes Almost always integrate HTML forms, allowing visitors to perform searches, provide feedback, and so forth Often have interfaces where administrators can manage the site’s content Are easier to maintain, upgrade, and build upon than statically made sites. 11/28/2019 BantamlakDejene,Information Technology 3
  • 4. Cont.…. There are many technologies available for creating dynamic Web sites. The most common are ASP.NET (Active Server Pages, a Microsoft construct), JSP (Java Server Pages), ColdFusion, Ruby on Rails (a Web development framework for the Ruby programming language), and PHP. Dynamic Web sites don’t always rely on a database, but more and more of them do, particularly as excellent database applications like MySQL are available at little to no cost. 11/28/2019 BantamlakDejene,Information Technology 4
  • 5. Server-Side Scripting Languages PHP originally stood for “Personal Home Page” as it was created in 1994 by Rasmus Lerdorf to track the visitors to his online résumé. As its usefulness and capabilities grew, it came to mean “PHP: Hypertext Preprocessor. According to the official PHP Web site, found at www.php.net A, PHP is a “widely used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.” It’s a long but descriptive definition. Server side refers to the fact that everything PHP does occurs on the server. A Web server application, like Apache or Microsoft’s IIS, is required and all PHP scripts must be accessed through a URL. Its cross-platform nature means that PHP runs on most operating systems, including Windows, UNIX, and Macintosh. More important, the PHP scripts written on one server will normally work on another with little or no modification. 11/28/2019 BantamlakDejene,Information Technology 5
  • 6. Cont.…. MySQL (www.mysql.com) is the world’s most popular open-source database. In fact, today MySQL is a viable competitor to the pricey goliaths such as Oracle and Microsoft’s SQL Server. Like PHP, MySQL offers excellent performance, portability, and reliability, with a moderate learning curve and little to no cost. MySQL is an RDBMS. A database, in the simplest terms, is a collection of data, be it text, numbers, or binary files, stored and kept organized by the DBMS. MySQL is an open-source application, like PHP, meaning that it is free to use or even modify. There are occasions in which you should pay for a MySQL license, especially if you are making money from the sales or incorporation of the MySQL product. The MySQL software consists of several pieces, including the MySQL server, the MySQL client, and numerous utilities for maintenance and other purposes. PHP always had good support for MySQL, and that is even truer in the most recent versions of the language. 11/28/2019 BantamlakDejene,Information Technology 6
  • 7. Use Basic Syntax <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Page Title</title></head> <body><!-- Example 1 - template.html --> </body></html> 11/28/2019 BantamlakDejene,Information Technology 7
  • 8. Cont.…. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Basic PHP Page</title></head> <body><!—Example 2 - first.php --> <p>This is standard HTML.</p><?php?></body></html> 11/28/2019 BantamlakDejene,Information Technology 8
  • 9. Send Data to Web Browser <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Using Echo</title></head> <body><!-- Example 3 - second.php --> <p>This is standard HTML.</p> <?php echo <p>This is generated by using PHP!</p> ?></body></html> 11/28/2019 BantamlakDejene,Information Technology 9
  • 10. Write Comments <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Comments</title></head> <body><?php # Example 4 - comments.php # Created March 16, 2011 # Created by Larry E. Ullman # This script does nothing much. echo '<p>This is a line of text.<br /> This is another line of text.</p>'; /* echo 'This line will not be executed.'; */ echo "<p>Now I'm done.</p>"; // End of PHP code. ?></body></html> 11/28/2019 BantamlakDejene,Information Technology 10
  • 11. Utilize Variables Regardless of what type you are creating, all variable names in PHP follow certain syntactical rules: A variable’s name must start with a dollar sign ($), for example, $name. The variable’s name can contain a combination of letters, numbers, and the underscore, for example, $my_report1. The first character after the dollar sign must be either a letter or an underscore (it cannot be a number). Variable names in PHP are case sensitive! This is a very important rule. It means that $name and $Name are entirely different variables. 11/28/2019 BantamlakDejene,Information Technology 11
  • 12. Cont.…. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN“ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Predefined Variables</title></head> <body><?php # Example 5 - predefined.php // Create a shorthand version of the variable names: $file = $_SERVER['SCRIPT_FILENAME']; $user = $_SERVER['HTTP_USER_AGENT']; $server = $_SERVER['SERVER_SOFTWARE']; // Print the name of this script: echo "<p>You are running the file:<br /><b>$file</b>.</p>n"; // Print the user's information: echo "<p>You are viewing this page using:<br /><b>$user</b></p>n"; // Print the server's information: echo "<p>This server is running: <br /><b>$server</b>.</p>n"; ?></body></html> 11/28/2019 BantamlakDejene,Information Technology 12
  • 13. Manipulate Strings A string is merely a quoted chunk of characters: letters, numbers, spaces, punctuation, and so forth. These are all strings: -> ‘Tobias’ -> “In watermelon sugar” -> ‘100’ -> ‘August 2, 2011 Make a string variable, assign a string value to a valid variable name: $first_name = 'Tobias'; $today = 'August 2, 2011'; When creating strings, you can use either single or double quotation marks to encapsulate the characters, just as you would when printing text. Likewise, you must use the same type of quotation mark for the beginning and the end of the string. If that same mark appears within the string, it must be escaped: $var = "Define "platitude", please."; Or you can also use the other quotation mark type: $var = 'Define "platitude", please.'; To print out the value of a string, use either echo or print: echo $first_name To print the value of string within a context, you must use double quotation marks: echo "Hello, $first_name"; 11/28/2019 BantamlakDejene,Information Technology 13
  • 14. Cont.…. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Strings</title></head> <body><?php # Example6 - strings.php // Create the variables: $first_name = 'ሐዲስ'; $last_name = 'አለማሁ'; $book = 'ፍቅር እስከ መቃብር'; // Print the values: echo "<p>The book <em>$book</em> was written by $first_name $last_name.</p>"; ?></body></html> 11/28/2019 BantamlakDejene,Information Technology 14
  • 15. Cont.…. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Strings</title></head> <body><?php # string concatenation, length and word counting => string_concat.php // Create the variables: $favoriteAnimal = 'cat'; $myArray ['age']= '28'; $about = "My age"; $len = strlen($about); $word = str_word_count("My favorite animals are {$favoriteAnimal}s"); // Print the values: echo "My favorite animals are {$favoriteAnimal}s => There are {$word} words in this sentence</br>"; // using curly bracket echo $about . " is " . $myArray["age"] . "</br>"; // using . operator echo "The length of " . $about . " is " . $len; ?></body></html> 11/28/2019 BantamlakDejene,Information Technology 15
  • 16. Cont.…. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Strings</title></head> <body><?php # string search and count => string_search.php // Create the variables: $su = 'Welcome to Samara University. Welcome to Department of Information Technology <br> This is the Department of Information Technology from College of Engineering and Technology in Samara University'; $search = strstr($su, "Engineering");// searches the string from the sentence $searchF = strpos($su, "University");// locates the string starting from beginning $searchE = strrpos($su, "Samara");// locates the string starting from end $count = substr_count($su, "Technology");//counts the repetition of the string in the text $countS = substr_count($su, "to", 9);//counts the repetition of the string in the text starting form the given index $countF = substr_count($su, "of", 45, 100);//counts the repetition of the string in the text between the indexes // Print the values: echo $su . "</br>"; echo "</br>Engineering is found at => ". $search . "</br>"; echo "University is found at => " . $searchF . " => from the beginning </br>"; echo "Samara is found at => " . $searchE . " => from the end </br>"; echo "Technology is repeated => " . $count . " => times in the text </br>"; echo "to is repeated => " . $countS . " => times in the text starting from index 9 </br>"; echo "of is repeated => " . $countF . " => times in the text between index 45 and 100 </br>"; ?></body></html> 11/28/2019 BantamlakDejene,Information Technology 16
  • 17. Cont.…. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Strings</title></head> <body><?php # string manipulation => string_manipulation.php // Create the variables: $myString = "It was the best of times, it was the worst of times"; $string = "Here's a little string"; $str = "Information Technology"; echo $myString . "</br></br>"; echo str_replace("times", "bananas", $myString, $num ). "</br>";//replaces all and count it echo "The text was replaced $num times. </br></br>"; echo substr_replace($myString, "bananas", 11 ). "</br></br>";//replaces from the given index echo substr_replace($myString, "bananas", 19, 5). "</br></br>";//replaces from the given index to the given number of characters echo substr_replace($myString, "really", 3, 0) . "</br></br>"; echo strtr($myString, " '", "+-"). "</br></br>"; echo strtolower($str) . "</br></br>"; echo ucfirst($str) . "</br></br>"; echo lcfirst($str) . "</br></br>"; ?></body></html> 11/28/2019 BantamlakDejene,Information Technology 17
  • 18. Cont.…. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head><title>Type Specifiers in Action</title > <link rel="stylesheet" type="text/css" href="common.css"></head> <body><h1>Type Specifiers in Action</h1> <?php $myNumber = 123.45; printf("Binary: %b </br>", $myNumber); printf("Character: %c </br>", $myNumber); printf("Decimal: %d </br>", $myNumber); printf("Scientific: %e </br>", $myNumber); printf("Float: %f </br>", $myNumber ); printf("Octal: %o </br>", $myNumber ); printf("String: %s </br>", $myNumber ); printf("Hex (lower case): %x </br>", $myNumber ); printf("Hex (upper case): %X </br>", $myNumber ); ?></body></html> 11/28/2019 BantamlakDejene,Information Technology 18
  • 19. Manipulate Numbers Work with Constants PHP has both integer and floating-point (decimal) number types. These two types can be classified under the generic title numbers without losing any valuable distinction (for the most part). Valid number-type variables in PHP can be anything like -> 8 -> 3.14 -> 10980843985 -> -4.2398508 -> 4.4e2 Notice that these values are never quoted—quoted numbers are strings with neither numeric values— nor do they include commas to indicate thousands. Also, a number is assumed to be positive unless it is preceded by the minus sign (-). Along with the standard arithmetic operators you can use on numbers (Table 1.1), there are dozens of functions built into PHP. Two common ones are round( ) and number_format( ). The former rounds a decimal to the nearest integer: $n = 3.14; $n = round ($n); // 3 11/28/2019 BantamlakDejene,Information Technology 19
  • 20. Cont.…. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Numbers</title></head><body> <?php # Script 1.8 - numbers.php // Set the variables: $quantity = 30; // Buying 30 widgets. $price = 119.95; $taxrate = .05; // 5% sales tax. // Calculate the total: $total = $quantity * $price; $total = $total + ($total * $taxrate); // Calculate and add the tax. // Format the total: $total = number_format ($total, 2); // Print the results: echo "<p/>You are purchasing </br>" . $quantity . "</br> widget(s) at a cost of <br>$" . $price . "</br> each. With tax, the total comes to <b>$" . $total . ".</br></p>"; ?></body></html> 11/28/2019 BantamlakDejene,Information Technology 20
  • 21. Cont.…. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Constants</title></head><body> <?php # Script 1.9 - constants.php // Set today's date as a constant: define ('TODAY', 'March 16, 2011'); // Print a message, using predefined constants and the TODAY constant: echo '<p>Today is ' . TODAY . '.</br> This server is running version <b>' . PHP_VERSION . '</b> of PHP on the <b>' . PHP_OS . '</b> operating system.</p>'; ?></body></html> 11/28/2019 BantamlakDejene,Information Technology 21