Check if PHP is using HTTPS (SSL)

I had to come up with a way to check if PHP is running in SSL mode today. This will work on both Apache, Nginx and IIS 1 2 3 4 5 6 7 8 9 10 11 12 function is_ssl() { $secure_connection = false;   if (!empty($_SERVER[’HTTPS’]) && $_SERVER[’HTTPS’] !== ‘off’ || $_SERVER[’SERVER_PORT’] == [...]

Posted on December 9th, 2011 by Wayne May in PHP | 0 comments

Detecting a Multi-Dimensional Array in PHP

I recently had to find a quick way to check if an array is a multi-dimensional array, only to find that there are no PHP built-in function to do this. Here is a quick and easy way to do it: 1 2 3 4 function is_multi_array( array $arr ) { return is_array($arr[key($arr)]); } This can [...]

Posted on December 9th, 2011 by Wayne May in PHP | 0 comments

Making a Radio Group Tab-able Using jQuery

Recently I had to come up with a solution to make radio boxes tab-able. Mozilla Firefox allows you to tab over each radio box in a group, however, all other browsers do not. The solution is actually quite simple. First, in your HTML make sure to name your radio boxes with the same name, but [...]

Posted on December 8th, 2011 by Wayne May in HTML & CSS, JavaScript | 0 comments

PHP Safe Redirect Function

I see PHP code every day making use of the header function. Its the standard way to make redirects in PHP, but will fail if ANY output was sent to the browser before its called. There is a safer way to do this, which use JavaScript and meta redirects as a fail safe: 1 2 [...]

Posted on December 8th, 2011 by Wayne May in PHP | 0 comments

PHP use Backticks as Execution Operators

PHP use backticks as execution operators, which will return the output of to be assigned to a variable. Any code between backticks will be executed as a shell command – the backtick operator is identical to shell_exec() One example where I found this useful was to get the fully qualified domain name of a server. [...]

Posted on December 7th, 2011 by Wayne May in PHP | 0 comments

Testing if a string is serialized in PHP

PHP offers a way to store arrays and objects through serialization. The problem is, there is no actual PHP function the check if data is serialized. I came up with a dirty little function to help with that: 1 2 3 4 function is_serial($data) { return (@unserialize($data) !== false); } unserialize will return FALSE if [...]

Posted on December 7th, 2011 by Wayne May in PHP | 0 comments

Create a custom feed in WordPress

Recently I was faced with the task to create various formats of the WordPress feed. My initial thought was to create a new “page” and use that as the feed. So you would call something like domain.com/custom-feed/ Then I found the add_feed() function: I could not find proper documentation for the function in the Codex, [...]

Posted on December 6th, 2011 by Wayne May in WordPress | 0 comments

Unlimited number of function parameters in PHP

Every so often I find myself needing to pass an unknown amount of arguments into a function. For example, assume you want to create a function to add a bunch of variables: add( $a, $b, $c, $d, … ) This can easily be done using the PHP function func_get_args(). 1 2 3 4 5 6 [...]

Posted on December 6th, 2011 by Wayne May in PHP | 0 comments

Converting from a RHEL install to a CentOS install

A couple of days ago I received a RHEL (Red Hat Enterprise Linux) Virtual Machine image from our IT support team. The problem was that the image was made using an evaluation copy of Red Hat. I figured I would convert it to CentOS, since there is no registration required. Here is what I did, [...]

Posted on December 5th, 2011 by Wayne May in Web Servers | 2 comments

Interfaces vs. Abstract classes in PHP

Many developers do not know the main difference between intefaces and abstract classes, since they seem to provide almost the same capabilities. Hopefully this will help you decide which to use in your application. When to use Interfaces? Interfaces allow you to specify which methods a class must provide, without having to know how they [...]

Posted on December 5th, 2011 by Wayne May in PHP | 0 comments