[Snippet] Clearing forms with Javascript
When creating forms on a website it is helpful to place descriptive text with some of the form fields to help the user understand what they should type in the box. I can never remember the Javascript to do it
- <input value="Username" onclick="this.value=''" type="text">
Messing with time and date on Linux
Some Linux distros don't come with time synchronisation utilities, even though Windows has done it since Windows 2000.
Here's how I solved the issue on a basic CentOS install.
Installing nginx & PHP-FPM securely on CentOS
I won't go into the reasons why you should install nginx, if you're here, you've already decided.
Here's how I installed nginx and PHP-FPM on CentOS.
MySQL Server on CentOS, what the RPM doesn’t do for you
Installing MySQL via YUM
Once the updates have finished we will be ready to install the MySQL server. Type the following command to install the MySQL server:
# sudo yum -y install mysql-server
Starting MySQL
Once the installation has finished we are ready to start our server for the first time. Upon initially starting it will create several test databases and the mysql system databases. To start the server type the following:
# sudo /etc/init.d/mysqld start
“sh: -t: command not found” with PHP cron/command line
Are you getting "sh: -t: command not found" when running a PHP from cron or command line? This usually occurs when your accessing PHP's mail() function with no (compatible) mail server installed on the server.
Here's my CentOS based solution.
Passing Every ~ \.php$ request to to PHP
It is common with Nginx to pass every URI ending in .php to the PHP parser, if using a default PHP build this might lead to security issues. Nginx is a reverse proxy and as such does not have a concept of file unless you specifically tell it to. So if your configuration looks like this.
[Snippet] Shopp Carousels & Slideshows
Carousels & Slideshows in Shopp can be a little tricky, the documentation isn't 100%.
- <?php
- shopp('catalog', 'onsale-products', 'load=true');
- shopp('category','carousel', 'duration=0&fit=all&imageheight=200&imagewidth=320');
- shopp('catalog','category','reset=true');
- ?>
or
- <?php
- shopp('catalog', 'featured-products', 'load=true');
- shopp('category','carousel', 'duration=0&fit=all&imageheight=200&imagewidth=320');
- shopp('catalog','category','reset=true');
- ?>
[Snippet] Formatting an IMEI Number in PHP
Formatting an IMEI
number in PHP is reasonably simple. The IMEI (14 decimal digits plus a check digit) or IMEISV (16 digits) includes information on the origin, model, and serial number of the device.
The format of the IMEI is AA-BBBBBB-CCCCCC-D, although it may not always be displayed this way. The IMEISV drops the Luhn check digit in favour of an additional two digits for the Software Version Number (SVN), making the format AA-BBBBBB-CCCCCC-EE
[Snippet] Simplified UK/US Date Conversion
One of my major annoyances in PHP & MySQL world is the different formats when working with dates.
US format: mm-dd-yy, UK format: dd-mm-yy and MySQL's date,datetime, timestamp columns yy-mm-dd. How do you cope with them all? I've been working on a rich UI recently which includes the jQuery date picker, by default thats in US format. UK users expect a date in UK format.



