Advanced Internet Programming Ch1
Advanced Internet Programming Ch1
ITec3092
Chala Simon
CHAPTER ONE:
SERVER-SIDE SCRIPTING
BASICS
Introduction to 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.
• Provide security since your server code cannot be viewed from a browser
Server-side Languages
o PHP
o ASP
o Ruby
o Python
o Java …
What is PHP?
PHP == ‘PHP: Hypertext Preprocessor’ –recursive acronym
7
PHP Features
• Performance: Script written in PHP executes much faster then those scripts written in other languages such
as JSP & ASP.
• Open Source Software: PHP source code is free available on the web. You can develop all the versions of
PHP according to your requirement without paying any cost. All its components are free to download and use.
• Platform Independent: PHP are available for WINDOWS, MAC, LINUX & UNIX operating system. A PHP
application developed in one OS can be easily executed in other OS also.
• Compatibility: PHP is compatible with almost all local servers used today like Apache, IIS etc.
• Embedded: PHP code can be easily embedded within HTML tags and script.
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.
• Using PHP, you can restrict users to access some pages of your website.
• To install PHP, AMP (Apache, MySQL, PHP) software stack is suggested. It is available for
all operating systems.
• WAMP for Windows
• XAMPP (Cross, Apache, MySQL, PHP, Perl) for Cross Platform: It includes some other
components too such as FileZilla, OpenSSL, Webalizer, Mercury Mail etc.
Web servers- xampp control panel
12
What does PHP code look like?
<?php
…
?>
Comments in PHP
# Shell-style comments
/* C-style comments
These can span multiple lines */
Variables in PHP
• All variables in PHP start with a $ sign, followed by the name of the variable.
• A variable name in PHP can only contain alpha-numeric characters and underscores
• Etc.
Variable usage
<?php
$abc = 'Welcome'; //valid
$Abc = 'W3resource.com'; //valid
$9xyz = 'Hello world'; //invalid; starts with a number
$_xyz = 'Hello world'; //valid; starts with an underscore
$_9xyz = 'Hello world'; //valid
The typical usage for this is to send data to the client’s web-browser
Syntax
• The variables in a function which keep their value after the function has ended.
<?php
function add() {
static $number = 1;
echo $number;
$number++;
}
add();
echo "<br>";
add();
echo "<br>";
add();
?>
PHP | Constants
• Constants are either identifiers or simple names that can be assigned any fixed values.
• They are similar to a variable except that they can never be changed.
Hello PHP
String functions
If the string has a set of double quotation marks that must remain visible, use the \
[backslash] before the quotation marks to ignore and display them.
<?php
$heading=“\”Computer Science\””;
Print $heading;
?>
“Computer Science”
Review exercise
What does a page’s encoding refer to?
What PHP functions, or language constructs, can you use to send data to the Web browser?
How does using single versus double quotation marks differ in creating or printing strings?
Search the PHP manual for the $_SERVER variable to see what other information it contains.
26
How are constants defined and used?
END