An Introduction to PHP3
One of the latest things to emerge in web development is a language called PHP. According to its proponents at http://www.php.net/, it is in use by Volvo, Red Hat, Miss USA 1999, First USA Bank, NASA JPL and other prominent organizations. One of its most popular applications is connecting to databases, but it can also talk to LDAP, IMAP and SNMP services, generate GIFs on the fly and do other tricks.
PHP3 is a server-side include scripting language and has been compared to Microsoft ASP (Active Server Pages), but with two differences crucial to me: it is open source and it runs on Linux. Actually, it is available under a GNU license or the PHP license, which allows commercial closed-source products to be developed from it. It runs on many UNIX platforms.
What is a server-side include? Think of it as another embedded language, like JavaScript, but which is converted to HTML (or images, JavaScript or other possibilities) on the server. The user's browser doesn't see the PHP code, just the results of executing it. This protects the developer's work, enhances security and bypasses things like conflicting implementations of JavaScript.
For example, the following code:
<HTML><BODY><?PHP echo "Hello, Net" ?></BODY></HTML>
in a PHP page on a PHP-enabled server will appear in the user's browser as Hello, Net.
What can PHP do for you? It greatly reduces the complexity of using cgi-bin variables and connecting to databases, and allows programming in an easy-to-learn language within web pages. It can do much more (the on-line reference lists 53 types of functions), but I will focus on database connectivity.
MySQL seems to be the most popular database to use with it, so I will use that for my examples. PHP can connect to Oracle, Sybase, PostgreSQL, Informix and other databases as well. It is important to note that PHP is not database-independent, unlike the DBI system used with Perl. You must use PHP functions tailored for the database you are targeting. This lets PHP access functionality available only in a specific database platform, but may reduce the portability of database-enabled projects.
In the following discussion, I will assume the reader has a knowledge of SQL, HTML and C.
I've already shown a “Hello, World” in PHP above. Note that the entire PHP code is embedded in a single tag within the HTML. The convention is to assign the extension .php3 to pages that should be pre-processed by PHP, although this is configurable. The page contains HTML (and whatever else the server and browser support, such as JavaScript) with one or more <?php ...php code... ?> blocks. As I mentioned above, the PHP is evaluated and its output sent to the browser, typically as HTML. PHP can also send any text language or even generate images on the fly.
The PHP blocks can be included anywhere in the HTML—even inside quotes or tags. For example, a link to another page could be produced from PHP. The following example:
<HTML><BODY> ... For more information, visit <A HREF= "<?php echo "moreinfo.html" ?>"> wacky link </A> </BODY> </HTML>
would work, although there is little point to it. The value of PHP is that it is a powerful programming language. It allows things like links to be generated by code. One can build a whole interactive web site with it.
PHP is much like basic C, a little like Perl, and has a few unique features of its own. Here are some key facts:
Variables are preceded by $ (just $, not @ or anything else).
Primitive types include integers, floats, strings, arrays, associative arrays and objects.
Type is usually set automatically, not in code, so there is no need to declare variables. They can be declared as static which makes them persist between PHP blocks on the same page.
//, /*..*/ and # are all used for comments—sort of a combination of C++, Perl and shell scripting.
Statements are terminated by semicolons.
Functions can be declared within a block. Their declaration and call resemble C.
Forms submitted to a PHP script pass in their variables (this is quite cool). They are accessible by name and also come in an array, which is nice when your calling form is a PHP program that may have unpredictable variable names.
The set of control structures and operators is very similar to C, although with some extensions.
There is limited support for object types.
Today’s modular x86 servers are compute-centric, designed as a least common denominator to support a wide range of IT workloads. Those generic, virtualized IT workloads have much different resource optimization requirements than hyperscale and cloud applications. They have resulted in a “one size fits all” enterprise IT architecture that is not optimized for a specific set of IT workloads, and especially not emerging hyperscale workloads, such as web applications, big data, and object storage. In this report, you will learn how shifting the focus from traditional compute-centric IT architectures to an innovative disaggregated fabric-based architecture can optimize and scale your data center.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
| Trying to Tame the Tablet | May 08, 2013 |
- Using Salt Stack and Vagrant for Drupal Development
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- New Products
- Validate an E-Mail Address with PHP, the Right Way
- Drupal Is a Framework: Why Everyone Needs to Understand This
- A Topic for Discussion - Open Source Feature-Richness?
- The Pari Package On Linux
- Home, My Backup Data Center
- New Products
- Developer Poll
Enter to Win an Adafruit Prototyping Pi Plate Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Prototyping Pi Plate Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- Next winner announced on 5-21-13!
Free Webinar: Linux Backup and Recovery
Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.
In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.




4 hours 5 min ago
9 hours 44 min ago
15 hours 43 min ago
16 hours 6 min ago
16 hours 16 min ago
16 hours 20 min ago
16 hours 50 min ago
19 hours 42 min ago
20 hours 17 min ago
20 hours 18 min ago