EchoFool Posted November 20, 2008 Share Posted November 20, 2008 Is there a way to get the page name that the function is in ..rather than the page the user is viewing? So example: index.php // code here include 'bleh.php'; //code and in the bleh.php has a function to get the name of that file which would return "bleh.php". Because at moment because its included in index.php im getting a result of index.php as a returned variable for function: strtolower($_SERVER['PHP_SELF']) What function should I use? Quote Link to comment https://forums.phpfreaks.com/topic/133514-get-page-name/ Share on other sites More sharing options...
flyhoney Posted November 20, 2008 Share Posted November 20, 2008 I'm not sure if this is possible. But consider this, if you are including the file that means at some point you explicitly know the name of the file you are including. So either save the name of the files you are including, or approach the problem you are having from a different angle. Just a suggestion. Quote Link to comment https://forums.phpfreaks.com/topic/133514-get-page-name/#findComment-694442 Share on other sites More sharing options...
Mark Baker Posted November 20, 2008 Share Posted November 20, 2008 Not sure if you want to try using __FILE__ Quote Link to comment https://forums.phpfreaks.com/topic/133514-get-page-name/#findComment-694454 Share on other sites More sharing options...
EchoFool Posted November 20, 2008 Author Share Posted November 20, 2008 Whats __FILE__ ? Quote Link to comment https://forums.phpfreaks.com/topic/133514-get-page-name/#findComment-694456 Share on other sites More sharing options...
Mark Baker Posted November 20, 2008 Share Posted November 20, 2008 __FILE__ is a PHP constant use echo __FILE__; and see what you get Quote Link to comment https://forums.phpfreaks.com/topic/133514-get-page-name/#findComment-694457 Share on other sites More sharing options...
flyhoney Posted November 20, 2008 Share Posted November 20, 2008 Yeah use __FILE__ The full path and filename of the file. If used inside an include, the name of the included file is returned. Since PHP 4.0.2, __FILE__ always contains an absolute path with symlinks resolved whereas in older versions it contained relative path under some circumstances Ignore my asshole comment from before $this_file_name = basename(__FILE__); Quote Link to comment https://forums.phpfreaks.com/topic/133514-get-page-name/#findComment-694460 Share on other sites More sharing options...
EchoFool Posted November 20, 2008 Author Share Posted November 20, 2008 Is there a way i can fut off the root folders from the file name as it has : /home/public_html/css/bleh.php Can it have a way to cut all of the folder names off leaving just bleh.php ? Quote Link to comment https://forums.phpfreaks.com/topic/133514-get-page-name/#findComment-694515 Share on other sites More sharing options...
premiso Posted November 20, 2008 Share Posted November 20, 2008 $file = basename($_SERVER['PHP_SELF']); basename Defaults returns only the page name. Quote Link to comment https://forums.phpfreaks.com/topic/133514-get-page-name/#findComment-694523 Share on other sites More sharing options...
npsari Posted November 20, 2008 Share Posted November 20, 2008 Sometime ago... I had a page /menu/index.php. In this page, I used the normal html layout, so, I a gave the page a title <head> <title>menu</title> </head> Everytime i included it, the overall page beocomes called 'menu' So perhaps this is what you should do, include the page first thing, then echo the page title Quote Link to comment https://forums.phpfreaks.com/topic/133514-get-page-name/#findComment-694551 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.