What Is a Members-Only Website?
Naming Conventions for Ruby on Rails
Accept Input to a Web Service

How to Create Base Functions for a Members-Only Website

The first step in creating any large application, such as a members-only website, is to create some base files that will be used to house generic functions. For this application, you use that validation file along with a main functions file that will then require other files.

The functions file will be responsible for starting sessions, setting up any constants that you might need, and including other required files. This saves you from having to remember what to include where and from having to remember to start sessions everywhere.

Your basic functions file will be called functions.inc and will be placed in the document root.

//generic file for generic functions and other includes

As you can see, the session is started and two files are required: the dbstuff.inc file and a validation.inc file, shown here:

function is_valid_state($state) {
        $validStates = array("AL","CA","CO","FL","IL","NJ","NY","WI");
        if (in_array($state,$validStates)) {
                return true;
        } else {
                return false;
} //end function is_valid_state
function is_valid_zip($zip) {
        if (preg_match('/^[d]+$/',$zip)) {
                return true;
        } else if (strlen($zip) == 5 || strlen($zip) == 9) {
                return true;
        } else {
                return false;
} //end function is_valid_zip
  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
How to Perform Basic JavaScript Validation
Secure PHP Applications with SuExec
How to Return XML Results
How to Return Web Service Data from a Database
How to Add JavaScript Validation to a Web Form

Inside Dummies.com