Online Test Banks
Score higher
See Online Test Banks
Learning anything is easy
Browse Online Courses
Mobile Apps
Learning on the go
Explore Mobile Apps
Dummies Store
Shop for books and more
Start Shopping

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 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 file and a 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

Inside Sweepstakes

Win $500. Easy.