miniflux-legacy/app/core/request.php

94 lines
1.7 KiB
PHP
Raw Normal View History

2013-02-18 03:48:21 +01:00
<?php
2016-08-25 03:17:58 +02:00
namespace Miniflux\Request;
2013-02-18 03:48:21 +01:00
function get_server_variable($variable)
{
return isset($_SERVER[$variable]) ? $_SERVER[$variable] : '';
}
2013-06-15 05:12:08 +02:00
function param($name, $default_value = null)
2013-02-18 03:48:21 +01:00
{
2013-06-15 05:12:08 +02:00
return isset($_GET[$name]) ? $_GET[$name] : $default_value;
2013-02-18 03:48:21 +01:00
}
2013-06-15 05:12:08 +02:00
function int_param($name, $default_value = 0)
2013-02-18 03:48:21 +01:00
{
2013-06-15 05:12:08 +02:00
return isset($_GET[$name]) && ctype_digit($_GET[$name]) ? (int) $_GET[$name] : $default_value;
}
function value($name)
{
$values = values();
return isset($values[$name]) ? $values[$name] : null;
2013-02-18 03:48:21 +01:00
}
function values()
{
if (! empty($_POST)) {
return $_POST;
}
$result = json_decode(body(), true);
if ($result) {
return $result;
}
return array();
}
function body()
{
return file_get_contents('php://input');
}
2014-02-08 20:13:14 +01:00
function file_content($field)
2013-02-18 03:48:21 +01:00
{
2014-02-08 20:13:14 +01:00
if (isset($_FILES[$field])) {
return file_get_contents($_FILES[$field]['tmp_name']);
2013-02-18 03:48:21 +01:00
}
return '';
2014-02-08 20:13:14 +01:00
}
function uri()
{
return $_SERVER['REQUEST_URI'];
}
2014-05-28 22:44:25 +02:00
function is_post()
{
return $_SERVER['REQUEST_METHOD'] === 'POST';
}
function get_user_agent()
{
2016-08-19 03:02:49 +02:00
return get_server_variable('HTTP_USER_AGENT') ?: 'Unknown';
}
function get_ip_address()
{
$keys = array(
'HTTP_X_REAL_IP',
'HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_X_CLUSTER_CLIENT_IP',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED',
'REMOTE_ADDR'
);
foreach ($keys as $key) {
$value = get_server_variable($key);
if ($value !== '') {
foreach (explode(',', $value) as $ip_address) {
return trim($ip_address);
}
}
}
2016-08-19 03:02:49 +02:00
return 'Unknown';
}