February 22, 2008

auto_prepend_file - Parse PHP before the requested PHP loads

You will find other articles relevant to this document in these sections:
Richard Lee @ 4:57 pm

Ever had to do some legacy hacking or changing of $_SERVER vars for different OS and wish you didn’t have to ruin your beautiful application? Well maybe auto_prepend_file is the answer! This is a little known core php directive, which when used  in a HTACCESS can let specify a php document to be parsed before the document that has been called is parsed - and for every document in the given directory for that matter. Personally I’ve been using it to set constants which may/ or may not be set and for workarounds when libraries dont exits, but even more simple use it to include a global config file with paths to various assets etc for your website ;)

February 12, 2008

Placing JavaScript correctly

You will find other articles relevant to this document in these sections:
Richard Lee @ 5:24 pm

How often do you visit websites with script errors? Frequently my Firebug Firefox Add-On lights up with “undefined” errors when I visit JavaScript intensive websites. Sure it doesn’t affect the functionality of the site (usually) but it’s just plain bad form, specially when it’s so easily avoided. Where you place your JavaScript should depend on how it is used in your site - Here’s some simple rules of thumb for placing JavScripts:

If the script needs to be run before the page is fully loaded to do some pre-processing for example such as browser and
resolution checks place the script in the header as this is always loaded before content in the body:

<head>
 
<style type="text/css" media="all">
@import "css/layout.css"
</style>
<script language='text/javascript'>
<!--
/*
For the purpose of example this script would load a stylesheet
based on the screen resolution.
*/
 
var width = screen.width;
var height = screen.height;
if (width < 1024) {
 document.write('<style type="text/css" media="all">@import "css/layout800×600.css"');
} else {
 document.write('<style type="text/css" media="all">@import "css/layout1024×768.css"</style>');
}
// -->
</script>
</head>

If the script manipulates html content the DOM must exist prior to the script execution. To make sure this is the case you can use the native window.onload() method which fires when the total document is loaded:

<head>
<script language='text/javascript'>
<!--
/*
For the purpose of example this script would create
a menu for the site
*/
 
function init_menu() {
 
   // do stuff here
 
}
window.onload = init_menu();
//-->
</script></head>

Or placing you could place your script /function call later in the document - usually just before the closing body tag:

 
<script language='text/javascript'>
<!--
init_menu();
// -->
</script>

I typically use the latter (before the closing body tag) because you can simply call multiple scripts relatively safely and avoid any window.onload() clashes since it is very possible other third-party scripts may be using this.

Update:

In addition to the above methods to make sure the DOM is loaded you can use the Prototype libraries “DOM ready”, dom:loaded event observer (which I have been using more recently) since it fires once the page markup has completed but before all the images etc have loaded:

document.observe('dom:loaded', function(){
 //any code here will be read once the DOM is ready, before images are loaded etc
});

And lastly, it’s always a good idea to check the DOM element(s) your targeting exist before you start manipulating them:

<script language='text/javascript'>
<!--
 
var glider = document.getElementById('glider');
if (glider != undefined) {
   // do stuff
 
}
// -->
</script>

February 7, 2008

Flint Interactive

You will find other articles relevant to this document in these sections:
Cameron Manderson @ 1:52 pm

Cameron Manderson is working for Flint Interactive, a young, independent, Melbourne-based interactive collective, offering fresh and innovative end-to-end web services. Draw together by a common vision to create awesome, inspiring and progressive online projects, their work and the way they go about it reflects their passion. more…

Making Firefox 2.0.0* extensions work in Firefox 3.0.2*

You will find other articles relevant to this document in these sections:
Richard Lee @ 11:10 am

I downloaded Firefox 3 beta 2 today. Give it a whirl i thought. But of course my beloved Web Developer and View Source Chart extensions were disabled because of incompatibility. I was almost about to revert back to 2, but being the stubborn person I am sometimes, I didn’t believe it so I did a bit of Googling and low and behold i stumbled upon some discussion on Mozilla about making the Greasemonkey add-on work under the new Firefox 3 beta - and it turns out all you need to do is hack the installation manifest to change the version compatibility . To summarize here’s what you need do :

  1. Download the xpi file of your plugin by right-clicking on the Install Now button and selecting Save Link As
  2. Right-click the downloaded my-extension-blah.xpi file and using 7-Zip select Open Archive (.
  3. Navigate to the install.rdf file and right-click and select Edit and find the maxVersion tag and change 2.0.0.* to 3.0.2.*
  4. Save your install.rdf file and close. Z-Zip will prompt if you want to update the archive so make sure you press ‘Yes’
  5. Finally open the file in Firefox, or drag it into a blank tab and the installation procedure begins as per normal.

Note: Please note i could only extract the and update the xpi package with 7-Zip, other zip programs didn’t repackage the xpi file properly, i kept getting errors when installing the package.

February 4, 2008

PHP 4 still kickin

You will find other articles relevant to this document in these sections:
Richard Lee @ 2:04 pm

Earlier this month the PHP dev team released 4.4.8 a security/ stability patch, supposedly the last patch of the 4 branch*. I was pretty surprised, as to my knowledge official support of version 4 had finished as of 2007. I’ve always commended the PHP dev team on their ongoing support for PHP 4 since so many apps and shared hosts still support PHP 4, but as developers we must move on, familiarity breeds content as they say, so if your thinking of updating to 4.8.8 I strongly recommend you GoPHP5.

Recommended reading on PHP 4 to PHP5 migration;