Category Archives: Website Development

PHP monitor server log

PHP monitor server log
Occasionally you'll be working on a webserver and not have SSH access to it. Below is a simple script I've written that reads a server log (in this case the error log) and outputs a portion of it to a webpage.
PLAIN TEXT
PHP:

$no_lines = 25;

 

$filename = $_SERVER['DOCUMENT_ROOT']."/../logs/error.log";

$handle = fopen($filename, "r");

$contents = fread($handle, filesize($filename));

fclose($handle);

 

$contents [...]

Mailto Hyperlinks Stop Spam Bots!

Everyone hates spam, I hate it even more than most people. If you put an email address on a website, as a mailto hyperlink, then it's likely that spam bots will find this address and start sending annoying emails.
One way to get around this is to use a clever technique which I discovered over at [...]

IE7 Clicky Sounds Do my Nut in!

I'm not a fan of applications that use sounds effects, one of the first things I do when configuring a new PC is to set the Windows Sound scheme to 'No Sounds'. IE7 has the hugely annoying feature where a click sound is made when you click a link with the middle mouse button (this [...]

PHP: File Downloads HTTP Headers

In PHP you can provide file downloads by using a PHP page to “pass through” the file. Of course you could just link to the actual file, however this technique means your file can kept outside of your website root. Another advantage is you can integrate this system into a PHP based user/password system easily.
Now [...]

PHP: Get First Index in Associative Array

The other day I was programming in PHP and needed to get the first index in an associative array. There doesn’t appear to be a built in function to deal with this so I wrote my own.
PLAIN TEXT
PHP:

function getArrayFirstIndex($arr)

{

foreach ($arr as $key => $value)

return $key;

}

Here's a bit of code you can test it on:
PLAIN [...]

JS: Execute JavaScript on Page Load

Recently I’ve been making an effort to improve my JavaScript skills, I’m not a JavaScript-Jedi yet but I have been picking up a few, tips, tricks and techniques.
One thing that I find extremely useful is using an init function to call other functions when the page has loaded. I have been using the nifty function [...]

Drupal: Hide Navigation on Forum

If you want to hide certain Navigational Blocks on your Drupal sites forum(s) here’s how to do it:
1. Go to "Administer » Blocks"
2. Click "configure" on the block you want to hide.
3. On Page specific Visibility Settings click the option for "Show if the following PHP code returns TRUE"
4. Enter the following code in the [...]

PHP: XOR swap

The XOR swap lets you swap the value of integer variables without using a temporary variable, it's also slightly faster.
PLAIN TEXT
PHP:

$x ^= $y;

$y ^= $x;

$x ^= $y;

I can't actually think of a good reason Why you'd want to use this in PHP since memory isn't normally a big issue, however it might be good [...]

JS: Unobtrusive Select All Checkboxes

I wrote last week about how I’m trying to improve my JavaScript skills. As a small exercise I have written this function for unobtrusively selecting/deselecting checkboxes in a form.
PLAIN TEXT
JAVASCRIPT:

function selectAll(box)

{

// get the elements name

var id = box.id;

var name = /^([a-z]+)(_select_all)$/i.exec(id);

 

name = name[1];

 

re = new RegExp('^'+name+'_[0-9]+$');

 

// get the elements stauts

var state = box.checked;

 

// get the [...]

My volatile relationship with Javascript

I started work in web development in 2004 at this point in time JavaScript was hugely unpopular in terms of web trends, this is probably because it was mostly used for annoying pop-ups, animations and whole list of other horrendous Internet crimes. I can recall having a King Herod style culling of all JavaScript from [...]