Scott M. Mcdermott

UNIX Systems & Network Administrator
available for contract or salaried positions

safe.php

<?

/*
 * This seems like a piss-poor way to do varargs, but I don't know of a better
 * way in PHP.  The point of the function is to wrap header() and alert the
 * user if headers have already been sent, but header() can take a variable
 * number of arguments, so we have to pass them thereto somehow, if we end up
 * invoking it.  A better way to do this really should be found.
 */
function
xheader ()
{
        if (headers_sent())
                die("xheader: headers have already been sent\n");

        if (($n = func_num_args()) == 1)
                header(func_get_arg(0));
        else if ($n == 2)
                header(func_get_arg(0),
                       func_get_arg(1));
        else if ($n == 3)
                header(func_get_arg(0),
                       func_get_arg(1),
                       func_get_arg(2));
        else
                die("xheader: impossible number of arguments\n");
}