function base($path='') {
$run_script = dirname($_SERVER['SCRIPT_NAME']);
$http_url = rtrim('http'.':'.'//'.$_SERVER['HTTP_HOST'].str_replace('\\', '/', $run_script), '/').'/';
if(!empty($path))
$http_url .= $path;
return $http_url;
}Kullanımı;
echo base(); // eğer localhost'da çalışıyorsak çıktımız şu olacaktır. -> http://localhost/
echo base('css/style.css'); // çıktısı -> http://localhost/css/style.css----------------------------------
function prepare_http_get_query() {
$route = (empty($_GET['route'])) ? 'index.php' : $_GET['route'];
unset($_GET['route']);
$http_get_array_keys = array_keys($_GET);
$http_get_array_values = array_values($_GET);
foreach($http_get_array_keys as $key)
unset($_GET[$key]);
$route_array = explode('/', $route);
$route_pagename = $route_array[0];
$route_queries = array_values($route_array);
$_GET['route_pagename'] = $route_pagename;
$_GET['route_queries'] = $route_queries;
$last_route_queries = end($route_queries);
if(count($route_queries) > 0)
array_pop($route_queries);
$last_route_queries_array = explode('.', $last_route_queries);
$last_route_query_extension = end($last_route_queries_array);
if(count($last_route_queries_array) > 1)
array_pop($last_route_queries_array);
$last_route_queries = array('filename' => end($last_route_queries_array), 'extension' => $last_route_query_extension);
$_GET['route_queries'][] = $last_route_queries;
foreach($http_get_array_keys as $key => $value)
$_GET['request_queries'][$value] = $http_get_array_values[$key];
}Kullanımı;
# kilit dosyalarımızdan herhangi birinde bu fonksiyonu çalıştırmamız gerekiyor.
prepare_http_get_query();
# Daha sonra $_GET globalindeki değişkenleri daha düzgün bi' şekilde görebiliyoruz.
print_r($_GET);
# çıktısı
/*
Array
(
[route_pagename] => index.php
[route_queries] => Array
(
[0] => index.php
[1] => Array
(
[filename] => index
[extension] => php
)
)
)
*/
# herhangi bi' GET sorgusu yaparsak çıktımız böyle oluyor
/*
Array
(
[route_pagename] => index.php
[route_queries] => Array
(
[0] => index.php
[1] => Array
(
[filename] => index
[extension] => php
)
)
[request_queries] => Array
(
[get1] => 123
[get2] => 123
)
)
*/