Server.php in Anti Spam by CleanTalk 9.1.x
File
src/lib/Cleantalk/Common/Variables/Server.php
View source
<?php
namespace Cleantalk\Common\Variables;
class Server extends SuperGlobalVariables {
public static $instance;
protected function get_variable($name) {
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] : '';
}
if (in_array($name, array(
'REQUEST_METHOD',
))) {
$value = strtoupper($value);
}
if (in_array($name, array(
'HTTPS',
))) {
$value = strtolower($value);
}
if (in_array($name, array(
'HTTP_USER_AGENT',
'HTTP_USER_AGENT',
'SERVER_NAME',
))) {
$value = htmlspecialchars($value);
}
static::getInstance()
->remember_variable($name, $value);
return $value;
}
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') . '/';
}
public static function in_referer($needle) {
return self::has_string('HTTP_REFERER', $needle);
}
public static function is_post() {
return self::get('REQUEST_METHOD') === 'POST';
}
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');
}
}
Classes
Name |
Description |
Server |
Class Server
Wrapper to safely get $_SERVER variables |