<?php
/**
* Tracks execution of URL parameters for a local utility.
*
* This script analyzes URL parameters and logs their usage.
* It's designed to be integrated into a local utility environment.
*/
// Define a file to store the tracked parameters.
$logFile = 'parameter_log.txt';
// Function to log parameter usage
function logParameterUsage($parameters) {
global $logFile;
// Format the log entry
$logEntry = date('Y-m-d H:i:s') . " - Parameters: " . print_r($parameters, true) . "\n";
// Append the log entry to the log file
file_put_contents($logFile, $logEntry, FILE_APPEND);
}
// Get all URL parameters
$parameters = get_url_parameters();
// Log the parameters
logParameterUsage($parameters);
/**
* Retrieves all URL parameters from the query string.
*
* @return array An associative array of URL parameters.
*/
function get_url_parameters() {
$parameters = [];
// Get the query string
$queryString = $_SERVER['QUERY_STRING'];
// Check if there is a query string
if ($queryString) {
// Split the query string into individual parameters
$pairs = explode('&', $queryString);
foreach ($pairs as $pair) {
// Split each parameter into key and value
$parts = explode('=', $pair, 2); // Limit to 2 parts to handle = in value
if (count($parts) == 2) {
$key = urldecode($parts[0]); // Decode URL-encoded characters
$value = urldecode($parts[1]); // Decode URL-encoded characters
//Add to parameter array
$parameters[$key] = $value;
}
}
}
return $parameters;
}
//Example Usage (uncomment to test)
//$test_url = "http://localhost/utility.php?param1=value1¶m2=value2¶m3=value3%20with%20space";
//echo "Parameters: " . print_r(get_url_parameters(), true);
?>
Add your comment