thedigicraft / Atom.CMS

Atom.CMS
56 stars 52 forks source link

Clean urls fix. #117

Open creptor opened 9 years ago

creptor commented 9 years ago

In some cases php error is activated by default (or to search for issues) and you'll find that the clean url script has some errors when all the data is not entered and can cause confusion.

The best solution is to fix it, so the querys just work when there's data associated to the url... example:

http://localhost/user/matthew/edit?language=en&hobbies=art&sport=football

http://localhost/home

To fix this just replace your clean url script with this

function get_path(){
    $path=array();
    if(isset($_SERVER['REQUEST_URI'])){
        $request_path=explode('?',$_SERVER['REQUEST_URI']);
        $path['base']=rtrim(dirname($_SERVER['SCRIPT_NAME']),'\/');
        $path['call_utf8']=substr(urldecode($request_path[0]),strlen($path['base'])+1);
        $path['call']=utf8_decode($path['call_utf8']);
        if($path['call']==basename($_SERVER['PHP_SELF'])){
            $path['call']='';
        }
        $path['call_parts']=explode('/', $path['call']);
        if(array_key_exists(1,$request_path)){
            $path['query_utf8']=urldecode($request_path[1]);
            $path['query']=utf8_decode(urldecode($request_path[1]));
            $vars=explode('&',$path['query']);
            foreach($vars as $var){
                $t=explode('=',$var);
                if(array_key_exists(1,$t)){
                    $path['query_vars'][$t[0]]=$t[1];
                }
            }
        }
    }
return $path;
}

Is the same code with just a check right before the arrays, just tested and works