Initial commit.
This commit is contained in:
78
lib/php/monica/cgiemu.inc.php
Normal file
78
lib/php/monica/cgiemu.inc.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
// File name: cgiemu.inc.php
|
||||
// Description: PHP subroutines to set the CGI environment emulation
|
||||
// Date: 2007-08-31
|
||||
// Author: imacat <imacat@pristine.com.tw>
|
||||
// Copyright: Copyright (C) 2007 Pristine Communications
|
||||
|
||||
// Constant symbols
|
||||
if (!defined("_CGIEMU_SET")) {
|
||||
_set_cgi_emu();
|
||||
define("_CGIEMU_SET", true);
|
||||
}
|
||||
|
||||
// add_get_arg: Add a get argument to the end of an url
|
||||
function _set_cgi_emu()
|
||||
{
|
||||
// php-cgi can work on both web and console,
|
||||
// but only CLI has STDIN and STDERR
|
||||
define("IS_CGI", getenv("GATEWAY_INTERFACE") !== false);
|
||||
// Only work if we are not under CGI environment
|
||||
if (IS_CGI) {
|
||||
return;
|
||||
}
|
||||
// GATEWAY_INTERFACE
|
||||
if (!array_key_exists("GATEWAY_INTERFACE", $_SERVER)) {
|
||||
$_SERVER["GATEWAY_INTERFACE"] = "";
|
||||
putenv("GATEWAY_INTERFACE=" . $_SERVER["GATEWAY_INTERFACE"]);
|
||||
}
|
||||
// QUERY_STRING
|
||||
if (!array_key_exists("QUERY_STRING", $_SERVER)) {
|
||||
$_SERVER["QUERY_STRING"] = "";
|
||||
putenv("QUERY_STRING=" . $_SERVER["QUERY_STRING"]);
|
||||
}
|
||||
// REMOTE_ADDR
|
||||
if (!array_key_exists("REMOTE_ADDR", $_SERVER)) {
|
||||
$_SERVER["REMOTE_ADDR"] = "127.0.0.1";
|
||||
putenv("REMOTE_ADDR=" . $_SERVER["REMOTE_ADDR"]);
|
||||
}
|
||||
// REMOTE_HOST
|
||||
if (!array_key_exists("REMOTE_HOST", $_SERVER)) {
|
||||
$_SERVER["REMOTE_HOST"] = "localhost";
|
||||
putenv("REMOTE_HOST=" . $_SERVER["REMOTE_HOST"]);
|
||||
}
|
||||
// REQUEST_METHOD
|
||||
if (!array_key_exists("REQUEST_METHOD", $_SERVER)) {
|
||||
$_SERVER["REQUEST_METHOD"] = "GET";
|
||||
putenv("REQUEST_METHOD=" . $_SERVER["REQUEST_METHOD"]);
|
||||
}
|
||||
// SERVER_NAME
|
||||
if (!array_key_exists("SERVER_NAME", $_SERVER)) {
|
||||
$_SERVER["SERVER_NAME"] = php_uname("n");
|
||||
putenv("SERVER_NAME=" . $_SERVER["SERVER_NAME"]);
|
||||
}
|
||||
// SERVER_PORT
|
||||
if (!array_key_exists("SERVER_PORT", $_SERVER)) {
|
||||
$_SERVER["SERVER_PORT"] = 80;
|
||||
putenv("SERVER_PORT=" . $_SERVER["SERVER_PORT"]);
|
||||
}
|
||||
// SERVER_SOFTWARE
|
||||
if (!array_key_exists("SERVER_SOFTWARE", $_SERVER)) {
|
||||
$_SERVER["SERVER_SOFTWARE"] = PHP_OS;
|
||||
putenv("SERVER_SOFTWARE=" . $_SERVER["SERVER_SOFTWARE"]);
|
||||
}
|
||||
// session.save_path
|
||||
$sessdir = ini_get("session.save_path");
|
||||
if ($sessdir != "" && !is_writable($sessdir)) {
|
||||
// Use the temporarily working directory in user's home first
|
||||
$sessdir = getenv("HOME") . "/tmp";
|
||||
if (!is_writable($sessdir)) {
|
||||
// Use system temporarily working directory
|
||||
$sessdir = sys_get_temp_dir();
|
||||
}
|
||||
ini_set("session.save_path", $sessdir);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user