PHP Date Function

PHP, ASP No Comments »

The person that wrote the PHP Date function is a genious. I use it in almost every PHP application I write and its usage is so simple to work with. I have recently completed work on a booking calendar for www.tenerife-property-rentals.co.uk - which allows users to book any number of dates from an availability calendar. If it wasn’t for the mktime() and date(), it would have taken a long long time!

If anyone has an ASP alternative, please let me know.

Navigation through index.php template?

PHP No Comments »

A question I get emailed alot is “How do you do your Web site navigation all through your index.php file?” - or something along those lines. And the answer is really simple.

The dynamic navigation is quite simply a tiny bit of PHP code. I’ll talk you through it:

  1. Create an index.php page, this is your “template” and should include everything you want on every one of your pages (e.g. a menu, banner, header, footer etc).
  2. Where you want your page content to go (usually in the centre, below the header), put the following code (in your index.php):
    < ?php
    $page = trim(addslashes($_GET['page']));
    if(!$page)
            $page = "home";
    if(!file_exists($page.".html"))
            include("error.html");
    else
            include($page.".html");
    ?>
    
  3. Upload your index.php page.

That piece of code will simply include the “page.html” where page is the page you pass to the URL. If the page is not available, error.html will be shown. So to call the “script”, you would simply go to www.yoursite.com/index.php?page=XXX

Also, if no page is specified, it defaults to home.html instead of error.html

The new CJ Website Design can (temporarily) be viewed here: http://www.cj-hosting.com/cjdesign - it’s still in early development but should be up in the next week or so due to us moving servers. As you can see from it, we use a different technique on the new site - we use Apache URL Re-Writing techniques to literally re-write the URL to index.php?page=XXX format - pretty neat and search engine friendly, you might want to read more about this technique at the following sites:

I hope this answers the question!


© James Crooke 2000-2008
Entries RSS Login