PHP CLI GET

From Noah.org
Revision as of 19:57, 23 April 2008 by Root (talk | contribs) (New page: Category:Engineering Call a PHP script from either the CLI or through a web server via a GET request. <pre> require_once(dirname(__FILE__) . "/../../includes/conf.php"); header("cont...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Call a PHP script from either the CLI or through a web server via a GET request.

require_once(dirname(__FILE__) . "/../../includes/conf.php");

header("content-type: text/plain");
set_time_limit(0);

// This copies command-line parameters into the $_GET variable.
// This allows the script to be called from http GET or from the command-line.
if ($argv) {
    foreach ($argv as $k=>$v)
    {
        if ($k==0) continue;
        $i = explode("=",$v);
        if (isset($i[1]))
        {
            $_GET[$i[0]] = $i[1];
        }
        else
        {
            $_GET[$i[0]] = True;
        }
    }
}