class Server in Anti Spam by CleanTalk 9.1.x
Same name and namespace in other branches
- 8.4 src/lib/Cleantalk/Common/Variables/Server.php \Cleantalk\Common\Variables\Server
Class Server Wrapper to safely get $_SERVER variables
@package \CleantalkSP\Variables
Hierarchy
- class \Cleantalk\Common\Variables\SuperGlobalVariables uses Singleton
- class \Cleantalk\Common\Variables\Server
Expanded class hierarchy of Server
8 files declare their use of Server
- AntiCrawler.php in src/
lib/ Cleantalk/ Common/ Firewall/ Modules/ AntiCrawler.php - AntiFlood.php in src/
lib/ Cleantalk/ Common/ Firewall/ Modules/ AntiFlood.php - BootSubscriber.php in src/
EventSubscriber/ BootSubscriber.php - CleantalkFuncs.php in src/
CleantalkFuncs.php - Firewall.php in src/
lib/ Cleantalk/ Common/ Firewall/ Firewall.php
File
- src/
lib/ Cleantalk/ Common/ Variables/ Server.php, line 11
Namespace
Cleantalk\Common\VariablesView source
class Server extends SuperGlobalVariables {
public static $instance;
/**
* Gets given $_SERVER variable and save it to memory
*
* @param string $name
*
* @return mixed|string
*/
protected function get_variable($name) {
// Return from memory. From $this->server
if (isset(static::$instance->variables[$name])) {
return static::$instance->variables[$name];
}
$name = strtoupper($name);
if (function_exists('filter_input')) {
$value = filter_input(INPUT_SERVER, $name);
}
if (empty($value)) {
$value = isset($_SERVER[$name]) ? $_SERVER[$name] : '';
}
// Convert to upper case for REQUEST_METHOD
if (in_array($name, array(
'REQUEST_METHOD',
))) {
$value = strtoupper($value);
}
// Convert to lower case for REQUEST_METHOD
if (in_array($name, array(
'HTTPS',
))) {
$value = strtolower($value);
}
// Convert HTML chars for HTTP_USER_AGENT, HTTP_USER_AGENT, SERVER_NAME
if (in_array($name, array(
'HTTP_USER_AGENT',
'HTTP_USER_AGENT',
'SERVER_NAME',
))) {
$value = htmlspecialchars($value);
}
// Remember for thurther calls
static::getInstance()
->remember_variable($name, $value);
return $value;
}
/**
* Checks if $_SERVER['REQUEST_URI'] contains string
*
* @param string $needle
*
* @return bool
*/
public static function in_uri($needle) {
return self::has_string('REQUEST_URI', $needle);
}
public static function in_host($needle) {
return self::has_string('HTTP_HOST', $needle);
}
public static function get_domain() {
preg_match('@\\.(\\S+)/?$@', self::get('HTTP_HOST'), $matches);
return isset($matches[1]) ? $matches[1] : false;
}
public static function getHomeURL($scheme = null) {
return (self::isSSL() ? 'https' : self::get('REQUEST_SCHEME')) . '://' . self::get('HTTP_HOST') . '/';
}
/**
* Checks if $_SERVER['REQUEST_URI'] contains string
*
* @param string $needle needle
*
* @return bool
*/
public static function in_referer($needle) {
return self::has_string('HTTP_REFERER', $needle);
}
/**
* Checks if $_SERVER['REQUEST_URI'] contains string
*
* @return bool
*/
public static function is_post() {
return self::get('REQUEST_METHOD') === 'POST';
}
/**
* Determines if SSL is used.
*
* @return bool True if SSL, otherwise false.
*/
public static function isSSL() {
if (self::get('HTTPS') === 'on' || self::get('HTTPS') === '1' || self::get('SERVER_PORT') == '443') {
return true;
}
return false;
}
public static function getURL() {
return substr(self::getHomeURL(), 0, -1) . self::get('REQUEST_URI');
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Server:: |
public static | property |
Overrides Singleton:: |
|
Server:: |
public static | function | ||
Server:: |
public static | function | ||
Server:: |
public static | function | ||
Server:: |
protected | function |
* Gets given $_SERVER variable and save it to memory
*
* Overrides SuperGlobalVariables:: |
|
Server:: |
public static | function | ||
Server:: |
public static | function | * Checks if $_SERVER['REQUEST_URI'] contains string * * | |
Server:: |
public static | function | * Checks if $_SERVER['REQUEST_URI'] contains string * * | |
Server:: |
public static | function | Determines if SSL is used. | |
Server:: |
public static | function | * Checks if $_SERVER['REQUEST_URI'] contains string * * | |
Singleton:: |
public static | function | Constructor | |
Singleton:: |
protected | function | Alternative constructor | |
Singleton:: |
public | function | ||
Singleton:: |
public | function | ||
Singleton:: |
public | function | ||
SuperGlobalVariables:: |
public | property | * | |
SuperGlobalVariables:: |
static | function | * Checks if variable equal to $param * * | |
SuperGlobalVariables:: |
public static | function | * Gets variable from ${_SOMETHING} * * | |
SuperGlobalVariables:: |
static | function | * Checks if variable contains given string * * | |
SuperGlobalVariables:: |
protected | function | * Save variable to $this->variables[] * * |