CONTENTS
WHY USE PHP? 1
USING PHP ON APACHE AND UNIX 2
The php Extension 2
PHP CODE 3
Functions 3
Containers 3
PHP With Forms 4
POST and GET 5
Conditional HTML 6
PHP With E-Mail 8
A Note About Email 9
PHP With Files 9
Error Reporting 11
Write Access 11
Arrays 12
Accessing Array Data 13
Don’t Trust Anyone Outside 14
Sorting Arrays 15
Visitor Sessions 15
Requiring Cookies 17
Sessions and Security 17
The Program So Far 17
Creating Images On the Fly 18
Creating Your Own Functions 20
Optional Arguments 22
WORKING WITH MYSQL 24
Create the table 24
Create the Database 24
Create the Username and Password 24
Create the Table 24
Store the data 25
Display the data 26
CURLY BRACKETS 28
GNU FREE DOCUMENTATION LICENSE 29
0. Preamble 29
1. Applicability and Definitions 29
2. Verbatim Copying 30
3. Copying in Quantity 30
4. Modifications 31
5. Combining Documents 32
6. Collections of Documents 32
7. Aggregation With Independent Works 32
8. Translation 32
9. Termination 33
10. Future Revisions of this License 33
PHP: HYPERTEXT PROCESSOR 34
34
WHY USE PHP?
If you need to embed dynamic text into static text, you’ll find PHP extremely useful. It was
designed for this, and it excels at it. PHP is also very useful for integrating web pages with
databases.
The PHP scripting language resembles JavaScript, Java, and Perl, These languages all share a
common ancestor, the C programming language.
PHP is most different from JavaScript and Java. PHP is a server-side scripting language. All of
the “work” is done on the server. JavaScript (and Java) generally run on the client. They have
little access to the information that the server has, and mediated access to information on the
client. They can do lots of things on the client that PHP cannot. PHP has full access to the
information that the server has, and very little access to information that the client has. In fact, it
only has information that the client tells the server and that the server passes on to PHP. Because
it is on the server, however, PHP cannot be modified by the client. While you cannot necessarily
trust the information that the client gives to PHP, you can trust that your PHP is doing what you
told it to do. Because PHP is on the server end, your PHP scripts can affect your server—such as
by keeping an activity log or updating a database.
PHP and Perl often work side-by-side. These are both server-side. Where PHP excels at
embedding dynamic content, Perl excels at modifying (or “filtering”) streams of text. PHP excels
at putting things into documents, and Perl excels at finding things in documents. After you have
learned PHP, you may well find Perl useful for many tasks, especially for command-line tasks.
PHP has an advantage over Perl on most web sites because PHP is usually loaded as part of the
web server. When scripting languages “run”, the system has to first load the “interpreter” and
then “compile” the language into code that the machine can understand. When you tell PHP to
echo the current time to the web page, the computer needs to have your command translated into
numbers that it can understand. Because the PHP interpreter is already loaded as part of the web
server’s software, it is always running. This cuts out half of that process. The interpreter is
already loaded, and it can go directly to compiling the language into code. When web servers see
a request to run a Perl script, they usually have to first load the Perl interpreter. This happens
very quickly, but when there are thousands or tens of thousands of requests coming every
second, every “very quickly” can add up.
C programs are “pre-compiled”. They cut out both steps in that process: no interpreter is needed
because the program is already compiled into code the machine understands. Because of this,
however, C programs must be compiled every time you switch to a new machine. If you move to
a different host, you will usually have to recompile your C programs. Sometimes you’ll even
have to recompile your C programs when your ISP upgrades their server’s system software. And
many ISPs do not provide you with a C compiler. You’ll find that PHP is more “portable” than C
in this respect: if it works on one server, it will usually work on any other server that has it. Most
ISPs that provide server-side scripting provide PHP.










