Preventing Image Bandwidth Theft With .htaccess

21st April 2008

When people link to your images from their own site they are essentially using your bandwidth to show images on their site, this is also known as hotlinking.

The simplest way of preventing people from doing this is to add a .htaccess file to only allow locally linked images to be served. This checks the domain that is linking to your images by using the referrer and if the domain does not equal you own site then a different image is served, in this case blank.jpg.

Debug Your PHP Applications With Krumo

20th April 2008

Krumo is an open source plugin for your programs that is designed as a replacement to print_r() and var_dump(). These functions are used by developers (myself included) to find out what the program is doing. The main problem is that if there is a lot of data to look at the page can get a bit busy.

Cut A String To A Specified Length With PHP

17th April 2008

Cutting a string to a specified length is accomplished with the substr() function. For example, the following string variable, which we will cut to a maximum of 30 characters.

Get Functions And Variables Of An Object With PHP

16th April 2008

It is possible to find out what functions and variables are available from an object at runtime using the PHP functions get_class_methods() and get_object_vars().

Take the following class called testClass.

Getting The Current URI In PHP

15th April 2008

The $_SERVER superglobal array contains lots of information about the current page location. You can print this off in full using the following line of code.

The Final Keyword In PHP5

14th April 2008

PHP5 allows you to stop classes being extended or to stop child classes overwriting functions.

The first way to use the final keyword is to stop child classes from overwriting functions when they are created. This can be used to stop an important function from being overwritten. To use the final keyword here just add it to the start of function name.

Get MySQL Version Information Through PHP

13th April 2008

There is little syntactical difference between MySQL 4 and MySQL 5, but sometimes finding that difference can pinpoint a bug. The mysql_get_server_info() function will tell you what version of MySQL you are using. You can call it with no parameters, in which case it picks the most recently created MySQL resource, or with the resource handle created with mysql_connect().

Here is an example of how to use it.

Using Multiple Arguments To A Function With parse_str() In PHP

12th April 2008

Sending multiple arguments to a function can be done using a parameter string. This is just like a URL that has data encoded into it. For example, if you wanted to send two parameters (called parameter1 and parameter2) to a function then you would use the following string.

parameter1=value1&parameter2=value2

To use this in the function you create the function as normal with a single parameter. This single parameter is the string that will contain all of your arguments.

View Directory List After Entering

11th April 2008

When navigating the file structure in Unix/Linux environments you will often find yourself typing cd to change the directory and then immediately typing ls to see the contents of the directory.

It is possible to run ls automatically every time you run cd by adding the following commands to your .bashrc file.