Entries in Web (41)

Tuesday
Oct262010

How to Disable Share This Pop-ups

Recently I have been coming across annoying Share This pop-up windows on several of the blogs that I read.  If you happen to leave your cursor over the link for a second or two, a window pops up and obscures part of what you are trying to read.  If you use Firefox there is something you can do about it:

  1. Install the Adblock Plus add-on (if you haven't already done so)
  2. Open the Adblock Plus Preferences window: Tools > AdBlock Plus Preferences...
  3. Click Add Filter...
  4. Enter http://*.sharethis.com/*
  5. Click OK

There, a whole business model obliterated!

Note added 2010-10-29: I have come across some similar pop-ups that are sourced from different URLs, so I have also added the following to my AdBlock Plus filter list:

  • http://*.addthis.com/*
  • http://*.addtoany.com/*
Friday
Jun252010

Gitignore Files disappearing from CodeIgniter Captcha Directory

I am using Git to manage the development and deployment of a website built using CodeIgniter and Tank Auth. In order to prevent git status from flagging captcha image files created during testing, I have placed a .gitignore file into the captcha directory. This file contains the single line:

  *.jpg

However, the captcha plugin supplied with CodeIgniter is a bit overzealous when it comes to cleaning up expired captcha image files: it also deletes the .gitignore file. This happens even when the web-server does not have write access to the .gitignore file. On Linux (I don't know about Windows) to delete a file from a directory you only need write access to the directory, not to the file itself.

[See the update at the foot of this post for a much simpler fix than this one.]

My fix for this was to change the Codeigniter captcha plugin so it only deletes *.jpg files. In file system/captcha_pi.php I changed:

  while($filename = @readdir($current_dir))
{
if ($filename != "." and $filename != ".." and $filename != "index.html")
{
$name = str_replace(".jpg", "", $filename);

if (($name + $expiration) < $now)
{
@unlink($img_path.$filename);
}
}
}

to:

  while($filename = @readdir($current_dir))
{
$name = str_replace(".jpg", "", $filename, $count);

if ($count and ($name + $expiration) < $now)
{
@unlink($img_path.$filename);
}
}

I do not currently have the CodeIgniter cache or logging functions enabled, so I don't know if .gitignore files in the system/cache and system/logs directories will also suffer such deletions.

Tuesday
Jun152010

PhpMyAdmin not working in Ubuntu 10.04 Server

Yesterday I installed PhpMyAdmin on my Ubuntu 10.04 server but when I came to test it out I couldn't get it to work: I just got a 404 Not Found page instead of the PhpMyadmin login page.  I searched the web and followed up several possible solutions but they all eventually just fizzled out.  Then the answer suddenly came to me while I was watching this video: I had omitted to select the configure for Apache option during installation.  I remembered just assuming that Apache would be the default and just hit Return without thinking, but watching the video made me realize that you had to explicitly mark Apache with an asterisk before hitting return.  Simple, and I am rather annoyed that I fell for this.

Saturday
May222010

Learning CodeIgniter

I have just come across this series of videos on CodeIgniter by Shawn McCool:

Having worked my way through the first three, I can say that they are better organised and better presented than the more extensive CodeIgniter from Scratch series by Jeffrey Way and Burak Guzel.  In addition, McCool seems a more experienced developer and provides a lot of background details and explanations that Way & Guzel just skate over.  McCool's videos seem altogether more 'professional'.

If you are looking to learn CodeIgniter I would recommend that you use both McCool's and Way & Guzel's videos, along with the online Codeigniter User Guide, which is excellent.  I would suggest that you avoid the currently available books, which seem to be superficial and riddled with errors.  At least, be sure to read the reviews on Amazon.com before you spend money on any of them.

Wednesday
May122010

The CodeIgniter End-of-File Comment Convention

From the CodeIgniter User Guide:

The PHP closing tag on a PHP document ?> is optional to the PHP parser. However, if used, any whitespace following the closing tag, whether introduced by the developer, user, or an FTP application, can cause unwanted output, PHP errors, or if the latter are suppressed, blank pages. For this reason, all PHP files should OMIT the closing PHP tag, and instead use a comment block to mark the end of file and it's location relative to the application root. This allows you to still identify a file as being complete and not truncated.

INCORRECT:

<?php

echo "Here's my code!";

?>

CORRECT:

<?php

echo "Here's my code!";

/* End of file myfile.php */
/* Location: ./system/modules/mymodule/myfile.php */

I agree that it is a good idea to omit the PHP closing tag, and also to mark the end of file with a comment. But I think it is a bad idea to embed the name and location of the file in that comment. This introduces an unnecessary dependency between the internal contents of a file and its name and location. It should be possible to rename or move a file without having to change its contents. Embedding the file name and location make this impossible. This is particularly ironic as one of the first operations that many people perform after installing CodeIgniter is to move the application directory up one level (see the CodeIgniter video tutorials by Jeffrey Way, for instance).