Chapter 16: PHP and Dreamweaver MX

PHP stands for Hypertext Preprocessor, but the abbreviation comes from the original full name of Personal Home Page Tools. PHP has been around longer than most other application web servers, and it happens to be one of the technologies Microsoft doesn't like. It is nevertheless becoming incredibly popular for a couple of reasons. First, it's free. There are no license fees, no charges for downloading-simply no charges. Second, PHP is part of the open-source software movement.

Introducing PHP

PHP started out as a set of CGI (Common Gateway Interface) scripts created by Rasmus Lerdorf and released to the general public on June 8, 1995. At the time of this writing, you can see the original announcement at:$$ Lerdorf started the ball rolling on a product that has become amazingly popular in the last year. Figure 16.1 shows a NetCraft survey from that illustrates the dramatic usage growth PHP has experienced in recent years.

click to expand
Figure 16.1: PHP has become a popular web-scripting language since its release, and it continues to grow in popularity.

PHP, like ASP (Active Server Pages), ColdFusion, and others, is a scripting language that resides on your server and lets you create dynamic web pages. PHP works like the others in that you embed PHP code within your HTML (Hypertext Markup Language) pages and the server interprets the PHP, generates the HTML code, and hands it to the user's browser. But PHP differs from the others in that it really isn't tag-based. It's more like a traditional programming language in which you can define variables and functions on the fly. You can even make recursive functions (functions that can call themselves) in PHP.


In this chapter, we're exploring the latest release of PHP, PHP 4.

Why PHP?

Why would anyone want to use PHP? If it's not supported by a large company such as Oracle or Microsoft, why should we use it? Well, let's look at a few of the many reasons PHP runs on millions of websites.

PHP Is Free

PHP, from its first release, has been free. This means you don't have to spend hundreds to thousands of dollars to license a web package from Microsoft, Sun, Oracle, Netscape, or even Macromedia. For those on a budget, free can be a big reason for using PHP.

PHP Runs on a Free Web Server

PHP is available to run on just about every possible web server. It's even available to run on the new Mac OS X. But the server that PHP is basically wedded to is the free Apache Web Server from the Apache Software Foundation, found at The Apache Web Server runs on most Unix and Windows flavors, so it is available for almost all major platforms, including the new Mac OS X.

PHP is wedded to Apache in that it is built so that you can actually make PHP part of the Apache Web Server: you can actually compile PHP into the Apache Web Server. This makes it blindingly fast and stable. Normally, PHP sits "on top" of the web server, waiting to grab PHP commands from the web pages before the web server gets them. Being inextricably linked into the web server removes a layer of complexity that gives great performance boosts.

Apache is also a free web server, whose growth and stability are becoming legendary. It's already the leading web server, as Table 16.1 shows from a survey.



Number of sites using each web server in August

Aug. %

Number of sites using each web server in September

Sept. % %












































PHP Works with a Free SQL Database Server

MySQL, which we covered in Chapter 7, is a free database server. It's also fast and stable. You'll find "triad" packages all over the Internet that include PHP, Apache, and MySQL installation programs for various platforms. Visit your favorite web search engine and search for "php triad" to see what we mean. Or you can download the installation package from

PHP Is Open-Source Software

PHP is officially part of the open-source software movement, which encourages programmer, hacker, and code-tinkerer volunteers to freely copy and modify the code to make it better. Those that modify the code or create new features or modules for code submit their enhancements to the governing body of the software for inclusion into the next official release. Generally, open- source software is either free or inexpensive.

Open-source is great because you have basically the world of software developers working on a single product-potentially thousands and thousands of developers trying to improve a piece of software. There is a drawback though: generally, open-source software doesn't come with technical support. You can't pick up the phone, pay someone, and get your questions answered. However, with the Internet today, you can almost always find an answer or a lead to solve technical questions on just about every piece of popular software.

Open-source software also has a tradition of longevity and stability. Although corporate entities maintain tight reins on their software and tend to move slowly in patching bugs, the open-source movement tends to work much faster. Bugs are fixed sooner, and thus the product is more stable. Although corporate entities must make a profit in order to stay in business, open-source projects don't need to appease shareholders, so they're not necessarily going away any time soon.

PHP Is Basically a Traditional Programming Language

Unlike other web-development languages, PHP doesn't really have tags that you use to create its functionality. You'll see later in this chapter that even Dreamweaver MX doesn't provide a large number of button-inserted commands. We suspect this is because there really aren't tags for which you could assign buttons. The structure of PHP is C-like, so C programmers shouldn't have a problem learning PHP. But even though PHP has a traditional programming language structure, it's still relatively easy to learn.

Configuring PHP

PHP, like much of open-source software, has many configuration options. As you might expect, since you can compile PHP into the Apache Web Server itself or even compile a build for Windows, options control how your customized, compiled version will behave. You can decide whether to include XML (Extensible Markup Language) support, reside as an Apache module, build in database directories, include Java support, and so forth. All the options and their behavior are beyond the scope of this chapter, but you can find them at the PHP website (

PHP also uses an initialization file called php.ini, a portion of which is in Listing 16.1. This file contains lots of PHP startup options that let you quickly customize how some features of PHP should behave without your having to recompile the entire system. The php.ini file is well documented within for those of you interested in learning more about tweaking your PHP installation. But let's take a look at a few of the options that you might want to immediately adjust in your copy of PHP.

start sidebar
The php.ini-recommended File

PHP ships with the php.ini file set with default values tuned for a development and learning environment. PHP also ships with the php.ini-recommended file, which is set with default values tuned for a production environment. The PHP folks highly recommend that you use the php.ini-recommended file as the starting base for your production environments, since it tweaks performance and security issues.

end sidebar


start example
;;;;;;;;;;;;;;;;;;;; ; Language Options ;  ;;;;;;;;;;;;;;;;;;;;  ; Enable the PHP scripting language engine under Apache.  engine =On ; Allow the <-d? tag. Otherwise, only <-d?php and <script> tags are recognized.  short_open_tag = On ; Allow ASP-style <% %> tags.  asp_tags = Off ; The number of significant digits displayed in floating point numbers.  precision = 12 ; Enforce year 2000 compliance (will cause problems with non-compliant browsers)  y2k_compliance = Off ; Output buffering allows you to send header lines (including cookies) even  ; after you send body content, at the price of slowing PHP's output layer a ; bit. You can enable output buffering during runtime by calling the output  ; buffering functions. You can also enable output buffering for all files by  ; setting this directive to On. If you want to limit the size of the buffer  ; to a certain size, you can use a maximum number of bytes instead of 'On', as  ; a value for this directive (e.g., output_buffering=4096).  output_buffering = Off ; You can redirect all the output of your scripts to a function. For  ; example, if you set output_handler to "ob_gzhandler", output will be  ; transparently compressed for browsers that support gzip or deflate encoding.  ; Setting an output handler automatically turns on output buffering.  output_handler =
end example

The short_open_tag Option

This .ini option controls whether PHP uses a short version of the open PHP tag. Dreamweaver MX uses the long open tag (<?php>), which is what you should use as well. By default, short_open_tag

is on. We recommend you turn it off. When on, short_open_tag allows you to start PHP statements with just <? as an opening tag. This was used heavily in earlier versions of PHP, and rumor has it that this tag is going to be phased out, since it conflicts with some XML statements. Save yourself some future compatibility problems, and use the proper, long version.

The asp_tags Option

When set to on, this option allows you to use ASP-style tags (<% %>) as PHP-code delimiters. If you're running PHP in a Windows Internet Information Services (IIS) environment, you may get unpredictable results since, by default, ASP is active on newer installations of IIS. Therefore, make sure this option is set to off.

The output_buffering Option

The output_buffering option controls whether you can send HTTP (Hypertext Transfer Protocol) header information to the browser after you've sent body content. This means, for more practical purposes, it controls whether you can set a cookie in a page and then redirect from that page. You set the number of bytes to allow in an output buffer, so set this to a nice-sized chunk. PHP recommends 4096.

The allow_call_time_pass_reference Option

This option is basically another legacy option that controlled whether you could pass function arguments by reference. (The programmers out there know what this means. For you nonprogrammers, it basically means that any changes made to the variable through the function call persist when the function ends.) The preferred PHP method for specifying pass-by-reference behavior is now in the function call itself. We recommend you set this option to off.

The display_errors Option

In a learning or development environment, you typically want to see all the error information you can when your page crashes. However, you generally do not want to show that kind of information to someone visiting a production website. Error information might divulge security information such as database names, file paths on your web server, and so forth. Make sure this setting is off in your live PHP environment. (You can still trap errors using error_log.)

The log_errors Option

You typically use this in conjunction with display_errors. The default value in php.ini is off, but in a production environment, you'll want it turned on. This controls whether PHP logs errors to a file on your web server. This file is controlled by the error_log setting.

The error_log Option

This setting controls where errors in your site are logged. PHP will create the file with the filename you enter for this setting. Use this file to trap errors when you have display_errors set to off.

The error_reporting Option

The error_reporting option can use any of 12 constants that control whether PHP reports errors such as fatal errors, warnings, notices, and so forth. You can combine some of the constants to choose exactly the type of errors you want to know about using the following symbols: & (and), | (or), and ~ (not). For example,

error_reporting = E_ALL & !E_NOTICEtells PHP to show you all errors except notices. If you want to see only errors and no warnings whatsoever, use something like the following:

error_reporting = E_ERROR |E_CORE_ERROR|E_COMPILE_ERRORSee Figures 16.3 and 16.4 later in the chapter for a comparison of this behavior. For your production environment, we recommend you log all errors and warnings so that you can trap problems that occur on your live website.

Mastering Dreamweaver MX Databases
Mastering Dreamweaver MX Databases
ISBN: 078214148X
EAN: 2147483647
Year: 2002
Pages: 214 © 2008-2017.
If you may any questions please contact us: