PHP Coding Specifications

The following style guidelines are set forth by Digital Indigo Technologies. The specifications are in place to create a uniform coding technique across all Digital Indigo sites. These specifications follow general style rules, however they are designed to maintain maximum compatibility across the current infrastructure.

In various situations, such as maintenance to an existing site, they guidelines may not be applicable. However, all new sites produced, or co-authored by Digital Indigo and alliance or associated companies are expected to follow these style guidelines. Exceptions to this are permitted if a style change is requested by the customer, however the customer must be informed that maintenance and/or repairs to the site may have longer update times and that warranties from Digital Indigo may be void or altered due to syntax changes.

 
Variable Checking
1. Encode all special characters (&,>,<).
When displaying any variables in HTML, an htmlentities() function must be performed. This takes care of changing any special characters over to the appropriate HTML representation.
2. Encode all strings passed as GETS or POSTS.
Strings must be encoded if generated from the PHP code. This prevents spaces, + symbols, and other characters from causing errors as they are passed through multiple posts or gets..
3. Decode encoded strings only at end of process or as needed.
If possible decode encoded strings only when you are ready to process the information into a database or some other form of data manipulation. As the data gets passed through multiple stages of gets and posts, it should remain encoded, and only encoded once at all times..
 
Database
1. Use one central include file with DBMS connect info.
The basic connection to the DBMS, including username, password, and database name should be included in one standard file. This file should be included in all scripts making calls to the DBMS. If any connection info changes to connect to the DBMS it should only be necessary to change this single include file so that all scripts across the site can still connect to the DBMS.
2. Load data into unique variables, do not refer using only the array.
Do not use lines such as:
$array=mysql_fetch_row($results);
Instead load data into individual variables:
list($first_name,$last_name,$etc)=mysql_fetch_row($results);