($raw !== false && $code >= 200 && $code < 300), 'body' => $raw, 'code' => $code, 'err' => $err, ]; } function getUserAgent() { return $_SERVER['HTTP_USER_AGENT']; } function getIP() { // Default way to get IP $ip = $_SERVER['REMOTE_ADDR']; // Allow overrides via config.php in-case we use a proxy - https://docs.itflow.org/config_php if (defined("CONST_GET_IP_METHOD") && CONST_GET_IP_METHOD == "HTTP_X_FORWARDED_FOR") { $ip = explode(',', getenv('HTTP_X_FORWARDED_FOR'))[0] ?? $_SERVER['REMOTE_ADDR']; } elseif (defined("CONST_GET_IP_METHOD") && CONST_GET_IP_METHOD == "HTTP_CF_CONNECTING_IP") { $ip = $_SERVER["HTTP_CF_CONNECTING_IP"] ?? $_SERVER['REMOTE_ADDR']; } // Abort if something isn't right if (!filter_var($ip, FILTER_VALIDATE_IP)) { error_log("ITFlow - Could not validate remote IP address"); error_log("ITFlow - IP was [$ip] using method " . CONST_GET_IP_METHOD); exit("Potential Security Violation"); } return $ip; } function getWebBrowser($user_browser) { $browser = "-"; $browser_array = array( '/msie/i' => " Internet Explorer", '/firefox/i' => " Firefox", '/safari/i' => " Safari", '/chrome/i' => " Chrome", '/edg/i' => " Edge", '/opr/i' => " Opera", '/ddg/i' => " DuckDuckGo" ); foreach ($browser_array as $regex => $value) { if (preg_match($regex, $user_browser)) { $browser = $value; } } return $browser; } function getOS($user_os) { $os_platform = "-"; $os_array = array( '/windows/i' => " Windows", '/macintosh|mac os x/i' => " MacOS", '/linux/i' => " Linux", '/ubuntu/i' => " Ubuntu", '/fedora/i' => " Fedora", '/iphone/i' => " iPhone", '/ipad/i' => " iPad", '/android/i' => " Android" ); foreach ($os_array as $regex => $value) { if (preg_match($regex, $user_os)) { $os_platform = $value; } } return $os_platform; } function isMobile() { // Check if the user agent is a mobile device return preg_match('/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|opera mini|palm|phone|pie|tablet|up.browser|up.link|webos|wos)/i', $_SERVER['HTTP_USER_AGENT']); } // Redirect Function function redirect($url = null, $permanent = false) { // Use referer if no URL is provided if (!$url) { $url = $_SERVER['HTTP_REFERER'] ?? 'index.php'; } if (!headers_sent()) { header('Location: ' . $url, true, $permanent ? 301 : 302); exit; } else { // Fallback for headers already sent echo ""; echo ''; exit; } } //Flash Alert Function function flashAlert(string $message, string $type = 'success'): void { $_SESSION['alert_type'] = $type; $_SESSION['alert_message'] = $message; }