Stored as "php.html.doc" College of St. Catherine LIS 753
Lab Exercise -- PHP Instructions
Now it gets interesting. As we’ve talked about in class, XHTML is good for presenting information, but in the end it is only a flat markup language. You literally use XHTML to “markup” the text and graphics of your pages to give the browser instructions on how to display the text and graphics on that page. XHTML pages by themselves cannot accept any input from the user, and they can’t dynamically change based on outside information. Think about this: although good content is the true key to a good website, what web sites do you go back to again and again? Times up! I’ll tell you: you go back to the web sites that have good content and that you can interact with. This includes Amazon.com, Google.com, your favorite library catalog, the list goes on and on. What do you think? Should we try to create some interactive pages of our own? In order to create an interactive web page, you’ve got to know more than just XHTML. You’ve got to know a programming language. Lucky for you, St. Kate’s has put the most popular server side programming language onto its web server: PHP. As I’ve already noted in the lecture, PHP was invented in the early 90’s by Rasmus Lerdorf, and all he wanted to do was count the number of people viewing his resume. Today, PHP is now a full-fledged programming language on par with heavy weights like ASP and Java. And thanks to its popularity (and the fact that it is free), when you get your first job in the “real world” most likely the library you work at is also going to be using PHP. Learning a little about it now will definitely give you a leg up. And although PHP is great for helping people create interactive web pages, PHP can also do a lot of stuff behind the scenes to make your life as a fledgling webmaster a whole lot easier. For example, by using PHP includes we can create a standard “header” and “footer” that we can use on every page that we create from now on. Imagine never having to type all that XHTML crapola on your pages again, except for one page that you refer to on all of the pages on your site. Think of PHP includes as CSS on steroids. For our first foray into PHP we are going to learn how to create these wonderful includes and we are going to create a mail form. Some of you may be thinking this is pretty lame, but hey, we gotta start somewhere. Some of you may also be thinking that this is a lot like the Forms lab. The big difference between this and the Forms lab is that in this lab you will be creating both the form and the email script the form points to in the action. So let’s get started!
Step 1: Open Notepad (or Simpletext) and create a New document. Step 2: Type in the following code: <meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
Step 3: Save this document as header.php and FTP it to your directory on paradox.stkate.edu Let’s talk about this file a little bit. First of all you should notice that as far as XHTML documents go, it isn’t finished. It doesn’t include the closing or tags. Good catch. Luckily, this file will never be used by itself. It will always be used in conjunction with both a main body text type file, and a file called “footer.php.” “footer.php” is where we will complete our XTHML. Are you with me so far? Let’s take a look at a little more then. You should also note that we saved this file as “.php”. This is very important. This tells the server that it should be aware that some PHP code may be present in this file. If we had saved this file with the .html extension, the server would ignore any PHP code we included. A file that is saved as .php doesn’t have to have PHP code, but if you are including PHP code the file has to be saved as .php. Does this make sense? You’ll also note that header.php contains some funky coding that we’ve never seen before, most of which starts with “”. What this bit of code does is tells the server to parse this section of code as PHP while leaving the rest of the file alone, or as simple XHTML. Now check out the variable called $title. If you’ll recall from the lecture, a variable is a bit of code that acts as a container for a value we wish to use more than once. So, what is the value of this variable? Ah … good question. We haven’t specified what the value is yet. We will do that in another file down the road. But you may also want to note that once we do specify that value it will be both the title of the XHTML file, and it will appear at the top of the page in between some tags since we are printing it out in these areas of our code. Let’s move on to the next file.
Step 4: Open Notepad (or Simpletext) and create a New document. Type in the following code:
URL: http://www.stkate.edu
"; ?>