80 lines
2.0 KiB
PHP
80 lines
2.0 KiB
PHP
<?php
|
|
// File name: https.inc.php
|
|
// Description: Extended PHP subroutine to handle HTTPs operations
|
|
// Date: 2004-03-05
|
|
// Author: imacat <imacat@pristine.com.tw>
|
|
// Copyright: Copyright (C) 2004-2007 Pristine Communications
|
|
|
|
// Set the include path
|
|
if (!defined("INCPATH_SET")) {
|
|
require_once dirname(__FILE__) . "/incpath.inc.php";
|
|
}
|
|
// Referenced subroutines
|
|
require_once "monica/cgiemu.inc.php";
|
|
require_once "monica/server.inc.php";
|
|
|
|
// https_host: The default HTTPs host name
|
|
function https_host()
|
|
{
|
|
// Respect the pre-defined setting
|
|
if (defined("HTTPS_HOST")) {
|
|
return HTTPS_HOST;
|
|
}
|
|
|
|
// Use the fully-qualified domain name (FQDN)
|
|
define("HTTPS_HOST", fqdn());
|
|
return HTTPS_HOST;
|
|
}
|
|
|
|
// fqdn: The fully qualified domain name
|
|
function fqdn()
|
|
{
|
|
// Cache the result
|
|
static $cache;
|
|
// Return the cache
|
|
if (isset($cache)) {
|
|
return $cache;
|
|
}
|
|
|
|
// Use DNS look-up for the current host name
|
|
// Apaches implementation
|
|
if (is_apache()) {
|
|
$addr = $_SERVER["SERVER_ADDR"];
|
|
// Microsoft IIS implementation
|
|
} elseif (is_iis()) {
|
|
$addr = $_SERVER["LOCAL_ADDR"];
|
|
// Else, do DNS query
|
|
} else {
|
|
$addr = gethostbyname($_SERVER["SERVER_NAME"]);
|
|
}
|
|
// Reverse-DNS query for a fully-qualified domain name (FQDN)
|
|
$cache = gethostbyaddr($addr);
|
|
|
|
return $cache;
|
|
}
|
|
|
|
// is_https: Check if current scheme is HTTPS
|
|
function is_https()
|
|
{
|
|
// Cache the result
|
|
static $cache;
|
|
// Return the cache
|
|
if (isset($cache)) {
|
|
return $cache;
|
|
}
|
|
// Apache implementation
|
|
if (is_apache()) {
|
|
$cache = array_key_exists("HTTPS", $_SERVER);
|
|
// Microsoft IIS implementation
|
|
} elseif (is_iis()) {
|
|
$cache = array_key_exists("SERVER_PORT_SECURE", $_SERVER);
|
|
// Well, set port 443 to https and others to http.
|
|
// This is a bad approach. Avoid it whenever possible.
|
|
} else {
|
|
$cache = ($_SERVER["SERVER_PORT"] == 443);
|
|
}
|
|
return $cache;
|
|
}
|
|
|
|
?>
|