didgydont Posted September 12, 2009 Share Posted September 12, 2009 hi all i have done a $_SERVER['PHP_SELF'] wich makes /demo/index.php but i want it so no mater what i change the folder name to i get the name of the php file only so in this case index.php any ideas ? thank you all Link to comment https://forums.phpfreaks.com/topic/173969-solved-finding-the-name-of-the-current-page/ Share on other sites More sharing options...
mikesta707 Posted September 12, 2009 Share Posted September 12, 2009 $_SERVER['REQUEST_URI'] give that a try Link to comment https://forums.phpfreaks.com/topic/173969-solved-finding-the-name-of-the-current-page/#findComment-917019 Share on other sites More sharing options...
didgydont Posted September 12, 2009 Author Share Posted September 12, 2009 thank you for your promt reply but the still produces /demo/index.php Link to comment https://forums.phpfreaks.com/topic/173969-solved-finding-the-name-of-the-current-page/#findComment-917026 Share on other sites More sharing options...
mikesta707 Posted September 12, 2009 Share Posted September 12, 2009 hmm post your code. request_uri should return the page you are currently running code on. I've never seen it post the actual directory you are in Link to comment https://forums.phpfreaks.com/topic/173969-solved-finding-the-name-of-the-current-page/#findComment-917031 Share on other sites More sharing options...
didgydont Posted September 12, 2009 Author Share Posted September 12, 2009 this i what i put in im pretty sure when it is run in the root it produces just the file name like $_SERVER['PHP_SELF'] echo "<br><br>Filename is: " . $_SERVER['REQUEST_URI'] ; Link to comment https://forums.phpfreaks.com/topic/173969-solved-finding-the-name-of-the-current-page/#findComment-917035 Share on other sites More sharing options...
Zane Posted September 12, 2009 Share Posted September 12, 2009 straight from the manual http://us2.php.net/manual/en/reserved.variables.server.php echo " " .$_SERVER['REMOTE_HOST'] ." REMOTE_HOST "; echo " " .$_SERVER['REMOTE_PORT'] ." REMOTE_PORT "; echo " " .$_SERVER['SCRIPT_FILENAME'] ." SCRIPT_FILENAME "; echo " " .$_SERVER['SERVER_ADMIN'] ." SERVER_ADMIN "; echo " " .$_SERVER['SERVER_PORT'] ." SERVER_PORT "; echo " " .$_SERVER['SERVER_SIGNATURE'] ." SERVER_SIGNATURE "; echo " " .$_SERVER['PATH_TRANSLATED'] ." PATH_TRANSLATED "; echo " " .$_SERVER['SCRIPT_NAME'] ." SCRIPT_NAME "; echo " " .$_SERVER['REQUEST_URI'] ." REQUEST_URI "; Link to comment https://forums.phpfreaks.com/topic/173969-solved-finding-the-name-of-the-current-page/#findComment-917043 Share on other sites More sharing options...
didgydont Posted September 12, 2009 Author Share Posted September 12, 2009 thank you but that returns "/home/mydomain/public_html/nextfolder/demo/index.php" Link to comment https://forums.phpfreaks.com/topic/173969-solved-finding-the-name-of-the-current-page/#findComment-917046 Share on other sites More sharing options...
Zane Posted September 12, 2009 Share Posted September 12, 2009 well try Script_name or use the same one and enclose it with basename basename($_SERVER['SCRIPT_FILENAME']) Link to comment https://forums.phpfreaks.com/topic/173969-solved-finding-the-name-of-the-current-page/#findComment-917048 Share on other sites More sharing options...
didgydont Posted September 12, 2009 Author Share Posted September 12, 2009 i already had and it returned same as $_SERVER['PHP_SELF'] Link to comment https://forums.phpfreaks.com/topic/173969-solved-finding-the-name-of-the-current-page/#findComment-917050 Share on other sites More sharing options...
Zane Posted September 12, 2009 Share Posted September 12, 2009 seriously, what does your code look like Link to comment https://forums.phpfreaks.com/topic/173969-solved-finding-the-name-of-the-current-page/#findComment-917052 Share on other sites More sharing options...
didgydont Posted September 12, 2009 Author Share Posted September 12, 2009 <? $filename = $_SERVER['PHP_SELF'];?> <br><br>the url is :<? echo $_SERVER['HTTP_HOST']; ?> <br> the page is : <? echo $filename; if (strpos($filename, 'index.php') !== FALSE) {echo "you are at index.php";} echo "<br><br>Filename is: " . $_SERVER['SCRIPT_FILENAME'] . "<br>" . $_SERVER['SCRIPT_NAME'] ;?> what about this $filesn = str_replace('/demo/','',$_SERVER['PHP_SELF']); echo "<br>final: $filesn"; is it possible to do a wild card like '%/' i know that doesnt work but just trying to show you what im trying to do. Link to comment https://forums.phpfreaks.com/topic/173969-solved-finding-the-name-of-the-current-page/#findComment-917059 Share on other sites More sharing options...
didgydont Posted September 22, 2009 Author Share Posted September 22, 2009 <? this solved my problem $Filepath = $_SERVER['PHP_SELF']; $Filepath = preg_split('/\//', $Filepath, -1, PREG_SPLIT_NO_EMPTY); $countarray = count($Filepath); $countarray = ($countarray-1); foreach ($Filepath as $key => $fileloc) { if ($countarray==$key){echo "$fileloc";} } ?> Link to comment https://forums.phpfreaks.com/topic/173969-solved-finding-the-name-of-the-current-page/#findComment-923196 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.