[code=php]<?php

    /**
     * This function can be used to easily redirect users to a given location. With the second argument it is
     * also possible to redirect the user to his referring location, if available. Else the script will
     * redirect to the given location.
     *
     * @author Gerard Klomp <gerard.klomp@sitemasters.be>
     * @version 1.0
     * @license http://sitemasters.be/mit-license.txt MIT License
     * @param string $location The URL the user has to be redirected to
     * @param bool $gotoRefererIfAvailable Go to referer if available, default false
     */
    function redirect($location, $gotoRefererIfAvailable = false)
    {
        if ($gotoRefererIfAvailable && isset($_SERVER['HTTP_REFERER']))
        {
            $location = $_SERVER['HTTP_REFERER'];
        }

        header('location: ' . $location);
        exit;
    }