Occasionally Relevant Insights from a Software Builder


Using Deprecated Code in PHP 5

If you don’t have the time or inclination to update your PHP4 code to PHP5, you can get the deprecated functions to work properly (especially the authentication code) by creating an .htaccess file and dropping it in the folder where your apps reside.

The .htaccess file should contain the following code:

php_flag register_globals on
php_flag register_long_arrays on

What this means is the following.


When this is set on, any variables that you pass to a web page through a URL (i.e. or post data, or a cookie will be set as a global variable in the PHP script.

The site states that “when on, register_globals will inject your scripts with all sorts of variables, like request variables from HTML forms. This coupled with the fact that PHP doesn’t require variable initialization means writing insecure code is that much easier.”

This is not a secure way to write software and the functionality was deprecated starting in PHP 4.2.0. The code needs to be replaced using $_GET, $_POST, $_COOKIE, or $_REQUEST.


This is another bad way of writing PHP code and also deprecated by the PHP team. To quote again, this “tells PHP whether or not to register the deprecated long $HTTP_*_VARS type predefined variables. When On (default), long predefined PHP variables like $HTTP_GET_VARS will be defined. If you’re not using them, it’s recommended to turn them off, for performance reasons. Instead, use the superglobal arrays, like $_GET.”

You need to fix your code by using $_GET, $_SERVER, etc. as opposed to HTTP_GET_VARS, $HTTP_SERVER_VARS, etc.


Counting Rows in textarea

I wrote a snippet which counts the number of rows of text in an HTML textarea object. Its very useful if you need to display data outside of the textarea box.

I’ve got an example of a form and the PHP function it calls.

Filename: t.php

Filename: t_handler.php


Preventing File Locking in E-mail Attachment

I’m trying to attach a file to an e-mail that I’m sending using the SmtpClient class (from System.Net.Mail) using C# for ASP.NET. Everything works correctly, but the problem is that the file that was uploaded gets locked in the folder by Windows and I can’t delete it afterwards.

This is the code I used to attach a file to an e-mail:

sHtmlConfirmation = "D:\\ftpsite\\from_web\\" + sFolder + "\\" + sFolder + ".htm";
Attachment data = new Attachment (sHtmlConfirmation);
Email.Attachments.Add (data);

I needed a solution to prevent Windows from locking a file that it uses, so I turned to the MSDN Forums for help. James Curran posted a working solution. He suggested employing the using statement to dispose the MailMessage object after the mail has been sent.

The code which fixes the problem is:

using (MailMessage Email = new MailMessage ())
// setup message details here

After the mail was sent, I was able to move the folder where the attached file was used.


Installing Flash Player in Fedora

I’ll admit that I’m not an expert on Linux. Proof of that was the difficulty I had in installing a Flash player for Firefox. I had no problems downloading the software, but during installation it asks where your web browser is to install the plugin. I’ve never been able to find exactly where Firefox gets installed in Fedora 6.

Fortunately, there’s yum to the rescue. The first thing you need to do is save the code below in the /etc/yum.repos.d/ folder under the filename macromedia-i386.repo.

name=Macromedia for i386 Linux

Then from a Linux terminal, enter the following command:

yum install flash-plugin

Then you’ll have the Flash plugin working with Firefox.


Installing Firefox 2.0 on Fedora 6

For those people who are still using Fedora 6 (version 8 is the latest), its possible to upgrade Firefox from version 1.5 to 2.0. You can download Firefox from Mozilla, but its a gzipped file and its easier working with an RPM. Red Hat doesn’t provide an RPM for this version, but you can use yum for the installation with the following procedure.

Log in as root and use yum to install the program.

$ su root
$ yum --enablerepo=development install firefox