Title: IMTA 99
1PHP Hypertext Preprocessor
Ilker BEKMEZCI
Advanced Network Programming Bogaziçi University,
Fall 2000
PHP
2Introduction
- PHP, which stands for "PHP Hypertext
Preprocessor", is an HTML-embedded scripting
language. - Much of its syntax is borrowed from C, Java and
Perl with a couple of unique PHP-specific
features thrown in. - The goal of the language is to allow web
developers to write dynamically generated pages
quickly.
Ilker BEKMEZCI
PHP
3Introduction-Example
- Different from CGI
- Different from Javascript.
lthtmlgt ltheadgt lttitlegtExamplelt/titlegt
lt/headgt ltbodygt lt?php echo "Hi, I'm a PHP
script!" ?gt lt/bodygt lt/htmlgt
Ilker BEKMEZCI
PHP
4Configuration
- The configuration file (called php3.ini in PHP
3.0, and simply php.ini as of PHP 4.0) is read
when PHP starts up. - For the server module versions of PHP, this
happens only once when the web server is started.
- For the CGI version, it happens on every
invocation.
Ilker BEKMEZCI
PHP
5Security
- The configuration file (called php3.ini in PHP
3.0, and simply php.ini as of PHP 4.0) is read
when PHP starts up. - For the server module versions of PHP, this
happens only once when the web server is started.
- For the CGI version, it happens on every
invocation.
Ilker BEKMEZCI
PHP
6Four ways of Escaping from HTML
- 1. lt? echo ("this is the simplest, an SGML
processing instruction\n") ?gt - 2. lt?php echo("if you want to serve XML
documents, do like this\n") ?gt - 3. ltscript language"php"gt echo ("some editors
(like FrontPage) don't like processing
instructions") lt/scriptgt - 4. lt echo ("You may optionally use ASP-style
tags") gt lt variable This is a shortcut
for "ltecho gt
Ilker BEKMEZCI
PHP
7Comments
PHP supports 'C', 'C' and Unix shell-style
comments. lt?php echo "This is a test" // This
is a one-line comment / This is a multi line
comment yet another line of comment / echo
"This is yet another test" echo "One Final
Test" This is shell-style style comment ?gt
Ilker BEKMEZCI
PHP
8Types
- PHP supports the following types array,
floating-point numbers, integer, object, string. - The type of a variable is usually not set by the
programmer rather, it is decided at runtime by
PHP depending on the context in which that
variable is used. - If you would like to force a variable to be
converted to a certain type, you may either cast
the variable or use the settype() function on it.
Ilker BEKMEZCI
PHP
9Variables
- Variables in PHP are represented by a dollar sign
followed by the name of the variable. The
variable name is case-sensitive.
Ilker BEKMEZCI
PHP
10Features-Creating/Manipulating images
- PHP is not limited to creating just HTML output.
It can also be used to create and manipulate
image files in a variety of different image
formats, including gif, png, jpg, wbmp, and xpm. - Even more convenient, php can output image
streams directly to a browser.
Ilker BEKMEZCI
PHP
11Features-Cookies
- PHP transparently supports HTTP cookies. Cookies
are a mechanism for storing data in the remote
browser and thus tracking or identifying return
users. You can set cookies using the setcookie()
function. - Any cookies sent to you from the client will
automatically be turned into a PHP variable just
like GET and POST method data.
Ilker BEKMEZCI
PHP
12Features-Connection Handling
- When a PHP script is running normally the NORMAL
state, is active. - If the remote client disconnects the ABORTED
state flag is turned on. A remote client
disconnect is usually caused by the user hitting
his STOP button. - If the PHP-imposed time limit is hit, the TIMEOUT
state flag is turned on.
Ilker BEKMEZCI
PHP
13Features-Persistent Database Connections
- Persistent connections are SQL links that do not
close when the execution of your script ends. - When a persistent connection is requested, PHP
checks if there's already an identical persistent
connection (that remained open from earlier) -
and if it exists, it uses it. If it does not
exist, it creates the link. - An 'identical' connection is a connection that
was opened to the same host, with the same
username and the same password
Ilker BEKMEZCI
PHP
14PHP vs. ASP?
- The biggest drawback of ASP is that it's a
proprietary system that is natively used only on
Microsoft Internet Information Server (IIS). - ASP is said to be a slower and more cumbersome
language than PHP, less stable as well. - Some of the pros of ASP is that since it uses
VBScript it's relatively easy to pick up the
language if you're already know how to program in
VB.
Ilker BEKMEZCI
PHP
15PHP vs. PERL?
- Perl was designed to do a lot more and can
because of this get very complicated. - PHP has a less confusing and stricter format
without losing flexibility. - Perl is a very tried and true language, it's been
around since the late eighties, but PHP is
maturing very quickly.
Ilker BEKMEZCI
PHP
16Questions
Ilker BEKMEZCI
TLI