WEB php_PROGRAMMIN2 SWE2
WEB php_PROGRAMMIN2 SWE2
WEB PROGRAMMING II
HND, Software Engineering
Year II / Semester II
What is FTP?
File Transfer Protocol, Transfers files between server and client
Its two Basic operations: Downloading and Uploading
Internet disadvantages
However, Internet has proved to be a powerful source of information in almost
every field, yet there exists many disadvantages.
Intranet
Intranet is defined as a private network that belongs to a particular organization.
It is designed for the exclusive use of an organization and its associates such as
employees, customers and other authorized people. So, it is like a private internet
that is operating within an organization.
It is based on the internet protocols (TCP/IP) and is protected from unauthorized
access with firewalls and other security systems. So, users on the intranet can
access the internet but the internet users can't access the intranet if they are not
authorized for it. Each computer in Intranet is also identified by a IP Address,
which is unique among the computers in that Intranet.
Extranet
Extranet refers to network within an organization, using internet to connect to the
outsiders in controlled manner. It is a communication network that is based on
internet protocols (TCP/IP). It helps to connect businesses with their customers
and suppliers and therefore allows working in a collaborative manner.
Benefits
Extranet proves to be a successful model for all kind of businesses whether small
or big. Here are some of the advantages of extranet for employees, suppliers,
business partners, and customers:
Skills Required
For being a successful web developer, one should possess the following skills:
Understanding of client and server side scripting.
Testing cross browser inconsistencies.
Conducting observational user testing.
Testing for compliance to specified standards such as accessibility
standards in the client region.
Programming interaction with javaScript, PHP, and Jquery etc.
browser requests a .html file (static content): server just sends that file
browser requests a .php file (dynamic content): server reads it, runs any
script code inside it, then sends result across the network
- script produces output that becomes the response sent back
So in Server side execution,
Code is scattered inside a html document
COURSE FACILITATOR : TATSOPTEU E. ENDELLY
9
tatsopt@gmail.com
The web server executes the code and produces a simple html page
PHP + MySQL
PHP combined with MySQL are cross-platform (you can develop in Windows
and serve on a Unix platform). The graphic below shows a basic workflow of
dynamic content being passed to and from the client using PHP combined with
database.
Why PHP?
There are many other options for server-side languages: Ruby on Rails, JSP,
ASP.NET, etc. Why choose PHP?
free and open source: anyone can run a PHP-enabled server free of charge
compatible: supported by most popular web servers
simple: lots of built-in functionality; familiar syntax
available: installed on UW's servers (Dante, Webster) and most commercial
web hosts
XAMPP window after a successful installation with Apache and MySQL enabled
Place your web project inside the htdocs directory. In the common case, if
you installed XAMPP directly inside the C: drive of your PC, the path to
this folder would be: C:xampphtdocs
To test the services are up and running you can just enter localhost in your
address bar and expect the welcoming page.
To see information about how PHP is configured, version information, and
the settings of all environment variables (e.g., HTTP_USER_AGENT and
QUERY_STRING), call the phpinfo()function in any script.
The php.ini file is the main configuration file for PHP. It can be edited by
the system administrator to change any of the configuration settings. A
change to this file requires the web server be restarted since the file is only
read once when the web server starts up. (The phpinfo()function reports the
location of php.ini on the server.)
PHP Basic Syntax
A PHP script can be placed anywhere in the document.
A PHP script starts with <?php and ends with ?>
Hello, World! Program
The following contents could go into a file hello.php:
PHP Constant
A constant is an identifier (name) for a simple value. The value cannot be changed
during the script. A valid constant name starts with a letter or underscore (no $
sign before the constant name). Constants are defined using define and by
convention are usually named in ALL CAPITALS.
a variable is NULL if
- it has not been set to any value (undefined variables)
- it has been assigned the constant NULL
- it has been deleted using the unset function
can test if a variable is NULL using the isset function
NULL prints as an empty string (no output)
String type
OPERATORS
Operators are special symbols to perform specific arithmetic logical operations
Assignment Operators
Comparison Operator
String Operator
Logical Operator
1. if ($x > 0)
$y = 5; // {} not required for only one statement
for loop
any contents of a .php file that are not between <?php and ?> are output as
pure HTML
can switch back and forth between HTML and PHP "modes"
Arrays
Arrays can have any size and contain any type of value. No danger of going
beyond array bounds.
$my_array[0] = 25;
$my_array[1] = "Bisons";
PHP arrays are associative arrays which allow element values to be stored
in relation to a key value rather than a strict linear index order.
$capitals["CO"] = "Denver";
$capitals["AR"] = "Little Rock";
Initialize an array:
$colors = array("red", "green", "blue");
print("The 2nd color is $colors[1]."); // prints green
$capitals = array("CO" => "Denver", "AR" => "Little Rock");
print("$capitals[CO]"); // prints Denver, no quotes around key inside ""
Print contents of an array for debugging:
print_r($colors);
produces:
Managing variables
isset ( ): determines whether a certain variable has already been declared
by PHP.
unset( ): “undeclares” a previously set variable, and frees any memory that
was used by it if no other variable references its value.
empty ( ): empty( ) may be used to check if a variable has not been declared
or its value is false.
Predefined System "Superglobals"
Provide access to key runtime data elements.
Set by and managed through web server run-time environment and
available to the script.
Maintaining State
To keep track of data between HTTP requests, data can be stored in cookies
using the $_COOKIE array, or it can be stored on the web server via
session variables in the $_SESSION array.
setcookie() and session_start() functions below must be called before any
other output is produced unless output_buffering is turned on in php.ini.
$_COOKIE: for accessing HTTP cookies which are stored on the client
and are transmitted back to the web server in every HTTP request.
1. By default, cookies expire with the session. Closing the browser (not
just the tab) ends the session. setcookie ("age", "21");
2. Cookies can be given expiration dates so they persist even after the
browser is closed:
// Cookie expires in 24 hours
setcookie ("name", "Betty", time() + 60 * 60 * 24);
3. Getting the value of a cookie:
echo $_COOKIE["name"]; // Print contents of name cookie
Note that $_COOKIE will not have values set from setcookie() until the
php script is requested after a call to setcookie.
4. Deleting a cookie:
setcookie("name", FALSE);
5. Warning: Since cookies are stored on the client, they should not be used
to store sensitive data.
$_SESSION: for accessing session variables which are stored on the web
server. Variables are associated with a unique session ID which is stored in
a cookie or passed in the URL if cookies are disabled. This technique is
ideal for storing sensitive data since the data is not stored on the client.
1. Create a session (and a session ID) if one doesn’t already exist:
session_start();
2. If you are curious what the session ID looks like: echo session_id();
Cookie Handling
A cookie is a small file that the server embeds on the user's computer. Each time
the same computer requests a page with a browser, it will send the cookie
too. With PHP, you can both create and retrieve cookie values.
A cookie is often used to identify a user.
A cookie is created with the setcookie() function.
The setcookie() function must appear BEFORE the <html> tag.
Setting Cookie
Session Management
A session is a way to store information (in variables) to be used across multiple
pages.
By default, session variables last until the user closes the browser.
Session variables hold information about one single user, and are available
to all pages in one application.
Session data is stored on web server.
Start Session
A session is started with the session_start() function. Session variables are
set with the PHP global variable: $_SESSION.
The session_start() function must be the very first thing in your document.
Before any HTML tags.
let's create a new page called "demo_session1.php". In this page, we start
a new PHP session and set some session variables:
With PHP, you can connect to and manipulate databases. MySQL is the most
popular database system used with PHP.
Insert data
SQL injection
Attacker guesses the format of a query, then exploits
- If the attacker is able to form a valid SQL query using one of the input
fields, then there may be unintended results
PROJECT