59 lines
1.6 KiB
PHP
59 lines
1.6 KiB
PHP
<?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', '');
|
||
}
|
||
}
|