Code Library

Mr PHP provides this code library as a way to share code snippets, tech solutions and various information that my be helpful to other coders and the programming community at large.

MySQL Backup Script

Here is what I use to make a backup library of MySQL daily that will keep backups for 30 days.

SWFUpload with cPanel and mod_security

I searched long and hard to find what was causing swfupload to fail on my cPanel, but work on my test environment so I thought I better save the result incase I need it again.

Apache Expires Headers with mod_expires

Quick example of how to set default expires headers.

2-Way MySQL Replication

Some notes and commands I want to keep handy the next time I setup MySQL replication.

Inner Resize Browser Window

This JavaScript function will resize the inside of a browser window to the dimensions provided.

Image Cache using phpThumb and htaccess

This code snippet will allow you to generate thumbnails of images by visiting a URL such as yoursite.com/thumbs/images/myimage.100x100.jpg. This will create a 100px * 100px thumbnail of yoursite.com/images/myimage.jpg. The image will be stored on your server in yoursite.com/thumbs/images/myimage.100x100.jpg so the next request for the same image will be loaded without loading php. This will give you a very fast image caching system.

Deep Array Reverse

Recursively reverses a multi-depth array.

Remove Array Nulls

Recursively removes array keys with null values.

Deep In Array

Function similar to in_array() but it recursively searches a multi-depth array.

Fully Qualified Domain Name and Base Path

This simple snippet will provide you with a HTTP or HTTPS Fully Qualified Domain Name URL and Base Path to your CakePHP installation. I use it for the HTML base tag.