From 6d8abbf391d751ecae65232e3e6d01bcb32e0207 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Wed, 28 Jul 2021 18:18:36 +0200 Subject: [PATCH] Always detect requested URL from REQUEST_URI It's permit to access raw URL parameter values without automatic urldecode when access using $_GET or $_REQUEST. Also add UrlRequest::get_param() method that allow to access raw parameters values (without any decoding). --- includes/url.php | 28 +++++++++++++++++----------- public_html/.htaccess | 2 +- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/includes/url.php b/includes/url.php index 43bcba1..cfd4df5 100644 --- a/includes/url.php +++ b/includes/url.php @@ -174,17 +174,6 @@ function url_match($pattern, $current_url=false, $methods=null) { * @retval string|false The current request URL or false if fail **/ function get_current_url() { - if (isset($_REQUEST['go'])) - return $_REQUEST['go']; - return detect_current_url(); -} - -/* - * Try to detect current requested URL and return it - * - * @retval string|false The current request URL or false if detection fail - **/ -function detect_current_url() { logging('DEBUG', "URL : request URI = '".$_SERVER['REQUEST_URI']."'"); $base = get_rewrite_base(); @@ -460,6 +449,23 @@ class UrlRequest { return array_key_exists($key, $this->url_params); } + /** + * Get request parameter + * + * @param[in] $parameter string The name of the parameter + * @param[in] $decode string If true, the parameter value will be urldecoded (optional, default: true) + * + * @retval mixed The value or false if parameter does not exists + **/ + public function get_param($parameter, $decode=true) { + if (array_key_exists($parameter, $this->url_params)) { + if ($decode) + return urldecode($this->url_params[$parameter]); + return $this->url_params[$parameter]; + } + return false; + } + /* * Get request referer (if known) * diff --git a/public_html/.htaccess b/public_html/.htaccess index 574927e..6b1eb2c 100644 --- a/public_html/.htaccess +++ b/public_html/.htaccess @@ -5,4 +5,4 @@ RewriteBase /eesyphp RewriteCond %{REQUEST_FILENAME} !-f # If the request is not for a valid link RewriteCond %{REQUEST_FILENAME} !-l -RewriteRule ^(.*)$ index.php?go=$1 [L,QSA] +RewriteRule ^ index.php [L]