vwlsupport/core/Request.php
kknobloch b294ceeec8
2025-04-21 21:34:26 +02:00

59 lines
1.6 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
class Request {
public static function post(string $key, mixed $default = null): mixed {
return $_POST[$key] ?? $default;
}
public static function get(string $key, mixed $default = null): mixed {
return $_GET[$key] ?? $default;
}
public static function hasPost(string $key): bool {
return isset($_POST[$key]);
}
public static function hasGet(string $key): bool {
return isset($_GET[$key]);
}
public static function allPost(): array {
return $_POST;
}
public static function allGet(): array {
return $_GET;
}
// Optional: Sanitize input
public static function postSanitized(string $key, mixed $default = null): mixed {
return htmlspecialchars($_POST[$key] ?? $default);
}
// Optional: Boolean inputs (z.B. Checkbox, Radio, etc.)
public static function postBool(string $key): bool {
return isset($_POST[$key]) && ($_POST[$key] === '1' || $_POST[$key] === 'true' || $_POST[$key] === 'on');
}
public static function server(string $key, mixed $default = null): mixed {
return $_SERVER[$key] ?? $default;
}
public static function isPost(): bool {
return self::server('REQUEST_METHOD') === 'POST';
}
public static function isGet(): bool {
return self::server('REQUEST_METHOD') === 'GET';
}
public static function clientIp(): string {
return self::server('REMOTE_ADDR', '0.0.0.0');
}
public static function userAgent(): string {
return self::server('HTTP_USER_AGENT', '');
}
}