PHP

How to create a basic PHP template

by Kev on 9 February, 2009

When you’re creating a website with lots of pages all using the same look and feel, headers, CSS etc, it obviously makes sense to create a simple template.

Begin by creating a page in XHTML/HTML that looks and works exactly as you wish. Now cut and paste the header into a new file and put it into a folder called /includes/ on your server. This should be saved as something like header.php. Don’t worry that it’s not actually PHP code, that doesn’t matter. Do the same thing for your main navigation (the navigation that will remain the same throughout). You could put that in header.php but I like to keep it separate just in case there are rare cases where the navigation isn’t needed on a particular page. If you have subnavigation that changes section by section isolate that and put it in its own php file and finally, do the same thing for your footer. [click to continue…]

Use Facebook to Comment on this Post

Apache

by Kev on 16 October, 2008

Let’s say that you want to add a file upload facility to your website via PHP. The key to this is to ensure that the permissions on the folder you are copying up to allow PHP to do the copying. This is a classic Gotcha that can waste a whole load of time.

The first thing you need to know is that the folder you’re copying up to must be “Owned” by “Apache” rather than the site owner. In other words, you need to set the permissions on the folder to be owned by Apache. This then leads onto the other question “what is the Apache OwnerID?”.

I spent a good couple of hours trying to find an answer to this question. The owner Id can be found in the configuration files but a MUCH easier way is to create a PHP file containing the line:

<?php
 echo phpinfo();
?>

Run this file in your browser, scroll down to the “apache2handler” section and you’ll see “User/Group” listed. The numbers next to this show first the OwnerId and then the GroupId (usually both the same). Use a tool such as BitVise Tunnelier to log into your web server and set the Owner and Group to this number and PHP will then be able to copy to that folder. Take care only to change ownership of those folders you specifically want to be able to upload files to.

Use Facebook to Comment on this Post

Let’s hear it for HEREDOC

September 8, 2008

I’ve been using PHP seriously for a while now, and overall I think it’s the most productive programming language I’ve ever encountered. However, one of the things, as a PHP programmer, you need to do on a regular basis is to output HTML to the browser in order to draw web pages. The problem is [...]

Read the full article →

PHPDesigner 2008

June 4, 2008

It seems that my endless search for the ideal PHP IDE has finally…er…ended. phpDesigner 2008 is the most promising environment I’ve seen and even though I’ve only just started using it, it’s already seen Zend Studio Pro and the treacle-like Zend Studio Eclipse confined to the recycle bin. Use Facebook to Comment on this Post

Read the full article →