Hi folks.
I've managed this code:
<?php
function url(){
$url= array();
$requestUri= $_SERVER['REQUEST_URI'];
$pathParts= pathinfo($requestUri);
$url['web_root']= $pathParts['dirname'];
if(strpos($requestUri, '?')===false){
return $url;
}
$queryString= explode('?',$pathParts['basename']);
if(strpos($queryString[1], '&')===false){
$frag=sanitize($queryString[1]);
$url[$frag[0]]= $frag[1];
return $url;
}
$frag= explode('&',$queryString[1]);
foreach($frag as $propValue){
$frag= sanitize($propValue);
$url[$frag[0]]= $frag[1];
}
return $url;
}
function sanitize($queryString){
$frag= explode('=',$queryString);
$frag[1]= filter_input(INPUT_GET,$frag[0],FILTER_SANITIZE_STRING);
return $frag;
}
/*
From konstrukt framework
*/
function normalizePath($path){
$path = trim($path, "/");
$parts = Array();
foreach (explode("/", $path) as $part) {
$part = urldecode($part);
if ($part == '..') {
if (count($parts) == 0) {
throw new Exception("Illegal path. Relative level extends below root.");
}
array_pop($parts);
} else {
$parts[] = urlencode($part);
}
}
return implode('/',$parts);
}
$url= url();
/*
For js, css etc ........
*/
var_dump($url['web_root']);
echo "<br>";
var_dump(normalizePath(implode('/',$url)));
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<a href="?page=home">home</a><br />
<a href="?page=home&actions=..">home</a><br />
<a href="?page=home&actions=De andea">home</a><br />
<a href="?page=home&actions=insert&id=12">home</a><br />
</body>
</html>
I'd like to use a think like this in a request class
so I'm asking for advice.
Any comments on how I should be doing this better would be gratefully appreciated 😃
EDIT
I noticed right now that with rewrite rules
doesn't work 🙁