Update tools.php

This commit is contained in:
Delirious
2024-02-22 18:17:37 -07:00
parent 47aab43617
commit 72585c4e45
+38 -1
View File
@@ -1,9 +1,16 @@
<?php
function get_base_url($url) {
$parsed = parse_url($url);
return $parsed["scheme"] . "://" . $parsed["host"] . "/";
if (isset($parsed["scheme"]) && isset($parsed["host"]) && !empty($parsed["scheme"]) && !empty($parsed["host"])) {
return $parsed["scheme"] . "://" . $parsed["host"] . "/";
} else {
logStackTrace();
return "";
}
}
function get_root_domain($url) {
return parse_url($url, PHP_URL_HOST);
}
@@ -137,4 +144,34 @@
return join($emoji);
}
function logStackTrace() {
// Get the stack trace
$stackTrace = debug_backtrace();
// Format the stack trace for logging
$logMessage = "Stack Trace: ";
foreach ($stackTrace as $index => $trace) {
// Skip the first entry as it's the current function call
if ($index === 0) {
continue;
}
// Build the log message for each stack frame
$logMessage .= "#{$index} ";
if (isset($trace['file'])) {
$logMessage .= "File: {$trace['file']} ";
}
if (isset($trace['line'])) {
$logMessage .= "Line: {$trace['line']} ";
}
if (isset($trace['function'])) {
$logMessage .= "Function: {$trace['function']} ";
}
$logMessage .= "\n";
}
// Log the stack trace to the error log
error_log($logMessage);
}
?>