Alternate If Statements In PHP

20th January 2008 - 2 minutes read time

If you have programmed in PHP for any amount of time then you will be farmiliar with the if statement. The syntax is as follows:

Aborting Connections In PHP

19th January 2008 - 2 minutes read time

Sometimes in PHP you will have to do some things that might take a little time. You will therefore have a little trouble with users closing the browser or moving to another page before the script has finished. In this case you will want to either continue to execute the script just shut it down depending on what the user has done.

JavaScript Working Text

18th January 2008 - 2 minutes read time

Letting the user now that something in the background is working is an essential part of website usability. If nothing at all happens then the user will more than likely either try again or go elsewhere. A good way of doing this is to have a little bit of text that says "Working" and animate dots behind it. Here is a function that will do this.

How To Read A Remote IP Address In PHP

16th January 2008 - 1 minute read time

PHP keeps certain variables to do with server and networking in an associative array called SERVER. To find out the remote address of a user you can use the array identifier REMOTE_ADDR. This is used in the following manner.

Setting php.ini Location In Apache

15th January 2008 - 1 minute read time

After installing PHP on Apache you can use the php.ini file to set various different options to do with PHP. When Apache starts it uses what is contained in this file to set up and run PHP.

On both Windows, Unix and Linux systems Apache will look in a number of default locations for the php.ini file before giving up. You can explicitly tell Apache 2.x where to look for the file by using the PHPIniDir directive in the http.conf file.

Some Useful Maths Functions In JavaScript

14th January 2008 - 3 minutes read time

All of the maths functions in JavaScript are kept in a handy object called Math, which contains a number of different functions.

To get the absolute value of a number use the abs() function.

Redirecting The Page In PHP

13th January 2008 - 2 minutes read time

To redirect the current page to a different location you use the header() function in the following way:

Highlight Code In PHP

12th January 2008 - 2 minutes read time

When printing off source code there is a handy function that will parse the code and produce nice looking syntax highlighted code. There are actually two functions you can use. The highlight_string() function takes a string as a parameter and will print the highlighted code. The highlight_file() function takes a file name as a parameter, the contents of which are printed off with highlighted syntax. For now I will concentrate on the highlight_string() function, but the output of these two functions is the same.

Multiple Google Analytics On Same Page

10th January 2008 - 1 minute read time

To set up multiple Google Analytics tags on the same page you need to use the _uff = false; command in between the unchinTracker() calls to reset the tracker for the next account. The urchinTracker() function will send information on the page visit off to Google Analytics.

Getting A Random Row From A PostgreSQL Table

10th January 2008 - 1 minute read time

To get a random row from a PostgreSQL database you need to use the RANDOM() function. This is similar to the MySQL function RAND() and will generate a new random number for each row and order them by that new number. This is used in conjunction with the LIMIT clause to limit the amount of returned rows to one.