Reputation: 163
I'm working on styling apache indexes via a header.php file included from an .htaccess file. I've got it to a good point, but I need to retrieve the current page title from the URL. All the php references point me to solutions that work for getting the "current page" which is the included php file itself, and not the directory in which it's indexing.
Using this works, but brings up the header.php:
$current_folder = basename(dirname(__FILE__));
Thoughts on how to pull this off?
Edit: Folder structure is like this, if it helps to make more sense:
/
/includes/header.php
/dir/directory_that_I_want_the_name_of/
The .htaccess pulls in header.php for each directory index, so I need to know how to get the current directory name, not where the header.php lives, which comes back with /includes/ or header.php in the examples that I've found. I need to be fetching directory_that_I_want_the_name_of.
.htaccess:
Options +Indexes
IndexOptions FancyIndexing
IndexOptions FoldersFirst IgnoreCase XHTML NameWidth=*
IndexOptions SuppressHTMLPreamble SuppressRules HTMLTable
IndexOptions IconHeight=16 IconWidth=16
IndexOptions SuppressDescription
HeaderName includes/header.php
ReadmeName includes/footer.html
Upvotes: 1
Views: 648
Reputation: 785276
I just recreated all of this setup and was able to get base dir-name using:
echo basename($_SERVER["REQUEST_URI"]);
in /includes/header.php
.
Make sure to have your .htaccess code like this:
Options +Indexes
IndexOptions FancyIndexing
IndexOptions FoldersFirst IgnoreCase XHTML NameWidth=*
IndexOptions SuppressHTMLPreamble SuppressRules HTMLTable
IndexOptions IconHeight=16 IconWidth=16
IndexOptions SuppressDescription
AddType text/html .php
Addhandler application/x-httpd-php .php
HeaderName /includes/header.php
ReadmeName /includes/footer.html
Upvotes: 1
Reputation: 12059
I am not 100% sure of your questions, but it sounds like you are looking for the URL/Directory of the page you are currently on, not the directory of the header?
What about:
$_SERVER['PHP_SELF'];
$_SERVER['REQUEST_URI'];
$_SERVER['SCRIPT_NAME'];
$_SERVER['SCRIPT_FILENAME'];
$_SERVER['DOCUMENT_ROOT'];
Those all give info about the current file open by the server based on the HTTP request it received.
Upvotes: 0