PHP and Dynamic Adult Web Sites
Research indicates that the PHP scripting language is the programming language of choice for World Wide Web developers. Easier to use than Perl and faster than the competition, PHP can turn a flat Web site into a dynamic, ever-changing online resource that combines the two most important features of the Internet: information and interactivity. Getting started with PHP is easier than you think. Connor Young talks about this fantastic scripting language and even shows you how to create your very first PHP script with only Notepad and four lines of code.Research indicates that the PHP scripting language is the programming language of choice for World Wide Web developers. Easier to use than Perl and faster than the competition, PHP can turn a flat Web site into a dynamic, ever-changing online resource that combines the two most important features of the Internet: information and interactivity. Getting started with PHP is easier than you think. Connor Young talks about this fantastic scripting language and even shows you how to create your very first PHP script with only Notepad and four lines of code.
Not long ago if you had asked me what PHP was I’d probably have told you it’s either an illegal drug or the latest kitchen counter cleaner. Despite this recently corrected ignorance of the PHP scripting language, there was a day and age when I actually considered myself a computer programmer; in my collegiate days many of my evenings were spent wearing flannel shirts and coding Turbo Pascal programs for hours and hours until the rising sun finally forced me into bed. I’m happy to say that I’ve left my coding days behind me – I tend to obsess when I’m forced to bed without having finished a piece of code I’m working on; it’s hard to rest when you have equations floating around in your head. Too lazy to learn the syntax for C++ or some other more valuable programming language, I turned my Pascal books in for HTML tutorials and concentrated instead on the artistic side of online entertainment. Yep, I’m talking about selling naked women to a worldwide audience. Yet a Web site is more interesting when it can produce dynamic content, so in the past to solve that problem I have relied heavily on third party Perl scripts and Javascript code. This past year has taught me quite a few neat tricks, however, and the sleepless nights, flannel shirts and Don Johnson shaving routine might again be in my future because relying solely on third party code is getting old.
When I first arrived at TheAdultWebmaster.com I noticed that the site used PHP code (instead of Perl) in all kinds of creative ways to help manage content and deliver a more dynamic Web site experience to its audience. Initially all this meant to me was that updating the site would be more of a pain in the ass than I was accustomed to – I wasn’t sure what my HTML editor would do to the PHP code and I was too lazy to test this, so I resorted to using WordPad as my editor of choice. Updating pages with WordPad isn’t all that difficult, but it’s a less enjoyable experience since all you get to stare at is a text page full of HTML code – it’s like being that sorry-ass dude in The Matrix who sits there looking at binary codes all day long. Who says adult Webmasters stare at naked women all day long?
THE RISE OF PHP
Some of you are probably still wondering just what PHP is, so we might as well get the description out of the way right now. According to php.net, PHP is “a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.” Of special importance there is this business of embedding PHP code into an HTML page, something we use with great results on TheAdultWebmaster.com. For Webmasters with little or no coding experience, you should find that PHP is a much easier-to-learn programming language than Perl. The syntax for PHP more closely resembles other programming languages, including Javascript, which makes learning both PHP and Javascript less confusing. Why would you want to learn two languages? PHP, like Perl and ASP, is a server-side language, and since some problems call for a client-side solution, it is still useful to be familiar with Javascript, a client-side scripting language, even if you have mastered PHP. If you were trying to decide which language to learn first, however, you’d do well to start with PHP.
As mentioned previously, PHP code can be mixed with HTML code to produce dynamic Web sites. In order for this to work, however, you’re going to have to serve up your pages from a Web server that already has PHP installed. Since almost half of the world’s Apache Web servers are already equipped with the PHP module, there may be nothing required on your part in terms of getting your server ready to handle PHP-enhanced Web pages. I know it sucks to hear this, but if you’re not sure about the presence of PHP on your Web server then you will need to check with your Web host. I have a dedicated server with a company in California, and I was recently happy to find that PHP 4 was already installed, leaving me only the task of writing code and uploading it to my Web server. If you have your own server and want to install the PHP module, you can find all the information you need at php.net in their online manual for PHP.
PHP: SOME PRACTICAL USES
What can you do with PHP? I hate to sound like a Disney commercial here, but that’s going to depend on your imagination. Yikes, I can’t believe I said that! Some practical examples of how you might use PHP include all the traditional uses of Perl, such as building counters, clocks, auctions, affiliate programs, mailing list managers, polls, Message boards, postcards, news headline retrieval and display systems, image galleries, random image display and even search engines. You might automate the content on your pay sites – throw a bunch of images into a directory then write a script that pulls a few images from this directory each day and makes them available to your members. This last example would ensure that your members have something new to look at each day they visit, yet the amount of work required from you is minimal.
“I just couldn’t get myself interested in Perl because it was unlike anything I had seen before, most Perl tutorials I came across seemed like they were written in binary, and I was too busy learning HTML, search engine marketing and other skills vital to operating an adult Web site.”
Learning a new programming language seems like a difficult and time-consuming task, but I find that I get such a kick out of seeing my code in action that if I can just get myself started I tend to learn quickly. I just couldn’t get myself interested in Perl because it was unlike anything I had seen before, most Perl tutorials I came across seemed like they were written in binary, and I was too busy learning HTML, search engine marketing and other skills vital to operating an adult Web site. Now that PHP has grabbed my attention, learning its syntax has been both enjoyable and simple. To prove this, and to help you get started with PHP, let’s write a very quick little piece of code that you can test on your own Web server. If it works then PHP is installed on your server and you’re ready to start learning PHP. So open Notepad to start. Any text editor will do, but do not use a word processor like Microsoft Word unless you are sure you know how to save the file as a text document as opposed to a word processor document. Word processor documents add formatting information that will confuse your server.
YOUR FIRST SCRIPT
The first line of your first script will be a simple tag that tells your Web server that PHP code will follow. So on line one of your text document type the following:
<?php
The second line will be a comment. Comments are ignored and will not affect the operation of your script, but they can be used to provide useful information to anyone that is looking at your script. In PHP, comments should be preceded by “//” without the quotes to instruct the server to ignore what comes next on that line. So add the following to the second line of your text document:
// Gee it’s nice of Connor to show us this neat script.
The next step for this script is to instruct the server to output a text message to the screen. So for line three of your text file, type the following:
echo (“I promise to read TheAdultWebmaster.com every day!”);
In the above statement, the command “echo” tells the server that you want it to display a message on the screen. Note the semi-colon at the end of line three? The semi-colon is used in PHP to mark the end of a statement. One more line to go. On line one you indicated that you were beginning your script, but now you need to tell the server that your script is finished. Add the following to your fourth and final line:
?>
All done. Your complete script should look like this:
<?php
// Gee it’s nice of Connor to show us this neat script.
echo (“I promise to read TheAdultWebmaster.com every day!”);
?>
Save this text file as “taw.php” then upload it to your Web server and load it with your browser. If the PHP module is installed on your server then you should see this:
I promise to read TheAdultWebmaster.com every day!
Don’t forget to keep your promise! If you are interested in purchasing a good book for PHP beginners, here’s one you might want to try:
http://shop.osborne.com/cgi-bin/osborne/0072133716.html
Connor Young is Editor-in-Chief of The ADULTWEBMASTER Magazine.