I’m trying to get the full URL not URI for the current page. I have made a menu system and want to set the relevant <li> tag as “current”.
All the urls in the menu system are using mod_rewrite so if I use $_SERVER[‘REQUEST_URI’] it will return something like - index.php?mod=user&page=dashboard. What I want to find is “http://www.domain.com/dashboard/”. Is it possible to get the URL instead of URI?
and you only want “dashboard” then you should be able to use something like this:
// spoofing your actual value for test purposes
$_SERVER['QUERY_STRING'] = "mod=user&page=dashboard";
parse_str( $_SERVER['QUERY_STRING'] , $output);
echo $output['page']; // dashboard
Then use that $output[‘page’] variable in your url string for your menu.
[fphp]parse_str[/fphp] man page contains sample I hacked that from
yea that won’t work either, otherwise I could just use $_GET[‘page’];
Basically I have a table with 100+ links in and I need to check if the link is the current active one - aka the url value equals the url for that page.
// spoofing your actual value for test purposes
$_SERVER['QUERY_STRING'] = "mod=user&page=dashboard";
function getThisPage(){
parse_str( $_SERVER['QUERY_STRING'] , $output);
return $output['page']; // dashboard
}
$thisPage = getThisPage();
if ($thisPage == $row['url'] ){
// bingo , its a match
}
The navigation goes 3/4 layers deep and it needs to be able to tell that. I guess my only option seems to be typing out the equivalent query string in the db as well.
function getThisPage(){
parse_str( $_SERVER['QUERY_STRING'] , $output);
if( isset($output['page']) ){
return $output['page']; // page if it set
}
elseif( isset($output['mod']) ){
return $output['mod']; // mod if it set
}else{
return ''; // return to index page onlu
}
}
Hi, This is the function I wrote that should work, I’ve used it on several sites:
// Get url of current page, including get vars - all url encoded so they can be passed as a single argument
// $use_get - if true then add $_GET arguments to end of filename
function get_this_page($use_get=false){
$files_arr = explode("/", $_SERVER["SCRIPT_NAME"]);
$thispage = $files_arr[count($files_arr)-1];
if (count($_GET) > 0 && $use_get == true) {
foreach ($_GET as $key => $value) {
$thispagevars = $key.'='.$value.'&';
}
$thispagevars = substr($thispagevars, 0, -5);
$thispagevars = '?'.urlencode($thispagevars);
}
else {
$thispagevars = '';
}
return $thispage.$thispagevars;
}
probably not the neatest way, but it’s worked with everything I’ve thrown at it.