PHP Tricks - Introduction to Programming
Part I - How to tell if your Web Server is running PHP
by Tad Coffin
MediaTitan.com
If your web site is on a web server that supports PHP, consider trying out a few simple PHP tricks or code snippets as an introduction to programming. How do you know if your web host supports PHP? Good question! It's very easy actually.
Use your favorite text editor, such as NotePad, and create a file named:
info.php
In this file, write the following line of code and save the file:
<? phpinfo(); ?>
Connect to your web host with an FTP program and upload the file to the root web directory, where you index page is. Open an Internet browser and go to the url of the page you just uploaded. It should be something like this:
http://www.yourdomain.com/info.php
If you see a nice screen with a bunch of technical information about your web server on it, congratulations! You have PHP installed on your web server. If you see something else, well, perhaps you should consider changing web hosts, or at least asking your server admin to instal PHP.
Now that you know you have PHP on your server, the fun begins. Before we go on though, let's take a look at what we did with info.php.
The first step to running a PHP script is to let the server know where the PHP code is. This is accomplished by tagging the beginning of PHP code with:
<?
//and tagging the end of PHP code with:
?>
Pretty simple, right? Now, PHP is really handy because you can insert it directly into regular HTML pages. Just change the .htm or .html extension to .php and ta-da! Your server will run your PHP code on the page.
So what's the echo all about? Glad you asked. The echo simply tells the server to print something. A page with the following code would produce a page with "Hello World!" on it:
<? echo "Hello World!"; ?>
The part that says phpinfo() is just PHP lingo for accessing all that data you saw on http://wwww.yourdomain.com/info.php Don't just take my word for it, see for yourself: http://www.php.net/manual/en/function.phpinfo.php
Now, although the punctuation is small, don't forget it. I am referring to the semi-colon (;) that ends each line of PHP code. Most of the time, forgetting the ; will mean the code won't work! (The echo function happens to be an exception.)


