Home > Computer > Application >

Reviews for PHP 4


Web Scripting in Action -  PHP 4 Application
PHP 4 

Newest Review: ... 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... more

Web Scripting in Action (PHP 4)

wulf

Member Name: wulf

Product:

PHP 4

Date: 14/09/01 (40 review reads)
Rating:

Advantages: Open Source, Flexible and Powerful, Opens up many more possibilities when building web pages

Disadvantages: Steep initial learning curve

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!

Summary:

Last members to rate this review:
(8 members total)

ILoveJackDaniels%2FGR-Design%2Frichardleonard%2FMuffin_the_Mule%2FScarlet_e_Tom%2Frob_writer%2F

View all 8 member ratings

Overall rating: Very useful

Nominate for a Crown:

See all newly Crowned Reviews

Last comments:
GR-Design

- 15/09/01

I wish I could do this sort of stuff. If I had the time too, I would start teaching myself the basics as once I've taught myself the basics in things, I can normally pick it up pretty quickly. Good luck with the NHS site by the way, it's the same kinda thing as I do :o)
wulf

- 15/09/01

It's a bit more picky about syntax (for example, you MUST end every statement with a semi-colon) but ASP has it's own pitfalls (why can you pass a subroutine one argument in parentheses, but more than one argument fails if you try to use parentheses? Frustrated me when I first hit it ;-)

Overall, it's good to be flexible, but if you are starting from scratch, I'd certainly give it a strong recommendation.
richardleonard

- 15/09/01

Sounds fun! I've taught myself ASP - although I know a bit of PHP - from what I've seen I think I prefer ASP - but good luck in your quest for knowledge!! RJL.

Product of the week
Top