1. <?php
  2. /**
  3. * Tracks execution of URL parameters for a local utility.
  4. *
  5. * This script analyzes URL parameters and logs their usage.
  6. * It's designed to be integrated into a local utility environment.
  7. */
  8. // Define a file to store the tracked parameters.
  9. $logFile = 'parameter_log.txt';
  10. // Function to log parameter usage
  11. function logParameterUsage($parameters) {
  12. global $logFile;
  13. // Format the log entry
  14. $logEntry = date('Y-m-d H:i:s') . " - Parameters: " . print_r($parameters, true) . "\n";
  15. // Append the log entry to the log file
  16. file_put_contents($logFile, $logEntry, FILE_APPEND);
  17. }
  18. // Get all URL parameters
  19. $parameters = get_url_parameters();
  20. // Log the parameters
  21. logParameterUsage($parameters);
  22. /**
  23. * Retrieves all URL parameters from the query string.
  24. *
  25. * @return array An associative array of URL parameters.
  26. */
  27. function get_url_parameters() {
  28. $parameters = [];
  29. // Get the query string
  30. $queryString = $_SERVER['QUERY_STRING'];
  31. // Check if there is a query string
  32. if ($queryString) {
  33. // Split the query string into individual parameters
  34. $pairs = explode('&', $queryString);
  35. foreach ($pairs as $pair) {
  36. // Split each parameter into key and value
  37. $parts = explode('=', $pair, 2); // Limit to 2 parts to handle = in value
  38. if (count($parts) == 2) {
  39. $key = urldecode($parts[0]); // Decode URL-encoded characters
  40. $value = urldecode($parts[1]); // Decode URL-encoded characters
  41. //Add to parameter array
  42. $parameters[$key] = $value;
  43. }
  44. }
  45. }
  46. return $parameters;
  47. }
  48. //Example Usage (uncomment to test)
  49. //$test_url = "http://localhost/utility.php?param1=value1&param2=value2&param3=value3%20with%20space";
  50. //echo "Parameters: " . print_r(get_url_parameters(), true);
  51. ?>

Add your comment