* Prices may differ from that shown
---> INTRODUCTION: I have decide to put together an opinion on one of the web's newest additions - an excellent tool for web programmers and designers called PHP. I've decided to split it into two sections - the first is an introduction which I'm keeping simple and non-techy ... and the second part is going to be full of stuff that makes no sense to people who get to go outside. ---> BACKGROUND: PHP, now in it's fourth version, is a scripting language used to create interactive websites. It is a very simple, very new, and very easy-to-use programming language that combines elements of tonnes of programming languages already used on the web (for example Java, Perl and C). PHP is an open-source language, which basically means it's free. It also means that most people who write using PHP will make what they've written available for free on the web. This means that people who don't have the time to spend learning a language will usually be able to find a program similar to the one they need already created on the web. It's a very easy language to learn. It takes about a week to gain a basic understanding of how to write scripts and set up databases, and that's with only a working knowledge of HTML. It takes about 2-4 weeks to be able to set up a website with a fully interactive member system and message boards etc. The actual reason PHP was written in the first place was to allow web developers to write dynamically generated pages quickly. If you are a web designer and have been thinking about learning to develop your own applications to use in your websites, then PHP is a gift from Heaven. It is extremely flexible and very easy to learn. For more information, you should have a look at www.php.net (which has lots of information and links for how to get started) or www.zend.com (who developed the fourth version of PHP). Altogether, what this means is that the development an
d growing popularity of PHP among programmers should see a greater number of website using interactive features, and a greater quality of interacticity overall on the web - which can't be a bad thing. ---> TECH-BABBLE: OK, so now I'm probably just talking to web-designers and similar "Outside? Where's that then?" types. You are probably wondering why you should listen to me and use PHP instead of Perl or Java or C++ or whatever you spent ages learning already. Well, if you've already learned a language or two, the chances are that the language you already know is more powerful than PHP. PHP is designed to be easy and fast to use, and as a result languages such as Perl can be used to create more powerful applications. Learning PHP is a doddle, as I've said above, and even more so if you know other languages. It borrows from Perl, C and Java, and users of these languages will find it very easy to pick up PHP virtually instantly. It works very well with databases (especially if you want to create a community based site), and MySQL and Access databases are both compatible and easy to use with PHP. PHP 4 is what I'm writing about, so it's would be a good idea for me to outline the basic differences between versions 3 and 4 (version 2 is now no longer used). PHP 4 has basically been written from the ground up, while based on PHP 3, to be faster and more efficient. PHP 3 tended to run very slowly with high-traffic sites, and PHP 4 has been written with high volume traffic in mind. There are also a large volume of new functions available with PHP 4. For example, PHP 4 supports FTP downloads and now recognises the 'Foreach' command (Perl programmers will recognise this). It is also backwards compatible, meaning those people who have written applications for use with PHP 3 will not have to re-write them from the ground up. Indeed, little or no modification wi
ll be needed to current PHP scripts. Finally, PHP 4 includes support for sessions, which should help PHP designers to create more secure and faster e-commerce enabled sites. ---> END TECH BABBLE PHP 4 marks a change in the way web pages will be written from now on. Gone are the days that Perl rules the interactive part of the web - now every man and his monkey can create a fully interactive web site in days, and with very little fuss or programming experience. Whether you are an experienced web-guru or just starting on your first hobby-site, you should consider using PHP 4 to run your site - you will not regret it.
In 2000, I started getting to grips with dynamic webscripting using Microsoft technology - VBscript in .asp pages. Having reached a good level of profiency with that, in 2001 I have been branching out and getting to grips with PHP4. Why learn a second approach? PHP is Open Source software, free to download and use. I prefer this from a philosophical standpoint and this instance the software built for love and liberty seems more powerful and flexible than the software built for profit; this is not least because I can run PHP on my Windows machine, but can't put .asp on my Linux box (not without paying a lot of money for the one program that might be able to do the job). Last year I redid my personal website using .asp pages (mainly as a way of helping me learn the technology); this year I have done the same again, but moving everything across to PHP. Take a look at http://www.web-den.org.uk/home/ and I will highlight some of the things PHP is doing behnd the scenes. 1. The whole look and feel of the page is dynamically generated. If you're using Internet Explorer or Opera, you will see a design involving several nested tables. If you look at the source code you will see this inevitably gets quite messy. However, should I want to make a change (either something small, like adding a new navigation button, or large, like creating a whole new look and feel) I don't have to do the same thing on every page of content. Instead, I update one central file that is used in the building of every page. Combining this with the use of cascading style sheets makes it very easy to maintain or alter the consistent appearance of the site. Each page of content consists of four sections: a) include('../referenceto/mypagebuilder.php'); This loads the tools needed to automatically create the page. b) writepagetop(); A function I've written to write the HTML head section and the consistent details at the top an
d left of each page. c) The page content (including the code for any other functions unique to that page) d) writepagebottom(); This writes the fixed content at the right and bottom of the page. 2. Text / Graphics Mode If you look at my page with Netscape, you'll get a plain white background and all the tables will have been removed - if I hadn't added the browser detection routine, you would just get a page of green leaves and nothing else at all! However, I've added a function that allows you to toggle between the full version and stripped down version at will. In order to pass this information from page to page I've made use of PHP4 session variables - these are one of the new features that PHP3 is lacking, but they make this kind of feature much easier to implement. You'd also use the same kind of trick if you wanted people to log into a website and then open up certain content to them; a session variable would let you know if a given page request came from an authorised user. 3. Current Date and Time Every time you load the page, you see an indication of the date and time in my part of the world. The changing content is expressed as follows: echo date("l j F Y @ g:ia"); The quoted string, "l j F ..." is giving PHP instructions to write particular parts of the current date and time (day of the week in full, day of month, month name in full, etc). It looks a bit cryptic, but I've found that PHP can handle date/time information much more flexibly than .asp. 4. Random quotation Every time the main page loads, it calls a function I've written to select a category of quotes for the current month. Each batch of quotes is stored in an XML file, and I use another function to read through the XML, extracting the name of the collection (shown in bold) and a random quote (between 10 and 20 options, depending on the particular XML
file). Reload the page a few times and you'll see what I mean. It's silly, but it's helped me develop a useful set of tools. Eventually I will also store the news items in an XML file and then use a PHP function to extract only those within the last couple of months, again reducing the time it takes to maintain the site. Having learnt how to use server-side scripting, I would find it very hard to go back to running a website made up of static pages. Having made use of two of the major scripting approaches, I would recommend looking into PHP first. There's nothing on this page that couldn't be done with a .asp page but some of the tasks (eg. formatting the date) were a lot easier and presented more options. If you want to learn more, I would suggest visting the official website (http://www.php.net/ , or the UK mirror http://uk.php.net) - the online manual is particularly helpful both to illustrate what can be done and as a reference tool when you're trying to do it yourself. Happy Scripting!