I would like to use PHP and *.inc files to add head, navigation and footer includes to help in site maintenance, (this part I have done). I would like to include the current page name as part of the 'head.inc' file, that is, when a user clicks on a link (or navigation button) to go to a page, php checks the url for that page ie "fredsite\home.php", and writes the name "Home Page" in the appropiate spot for that page. Can anybody point me in the right direction?
Thanks in advance.
write current url to page
Moderator: General Moderators
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
Think about it logically. To begin with the page doesnt know what it is loading. So you check the url. Now you know what page to load - but not what its called. So to find out what its called you must have somewhere a list to tell you what its called. What can hold a list? An array, a database.
So having found the page you are loading check it in an array or with the database to get the name.
So having found the page you are loading check it in an array or with the database to get the name.
-
Shendemiar
- Forum Contributor
- Posts: 404
- Joined: Thu Jan 08, 2004 8:28 am
Use javasript to recieve current document location (you need to get that data to php-variable and print it, ot use javascripts document.write)
You can receive the same info by global variables, but it's more complex
Use var_export($_SERVER); to examine this method
Code: Select all
<?php
echo "<SCRIPT TYPE="text/JavaSCRIPT"> \r\n";
echo "<!-- begin \r\n";
echo "alert(document.location);";
echo "// end -->\r\n";
echo "</SCRIPT>\r\n";
?>Use var_export($_SERVER); to examine this method
Thanks for the input, but I want to use PHP and not a combo. I just need the program to check the page name, and use "if" statements to go thru a list of pages, and then put match in variable, and then put that variable in current page to display that pages name, i.e.."Home Page", "Contact Us", or whatever it is. I do not want to change the underlying structure of the page, i.e.. the tables and columns, that is why I need PHP to insert the name. Can it be done?, any code snippets would be helpfull.
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
Code: Select all
switch($page_url){
case 'home.php':
$page_title = "Home";
break;
case 'contact.php';
$page_title = "Contact Us";
break;
}SOLVED
Thanks for all the input, I have tested the following code, and it works ok.
<?php
$page_url = ($_SERVER['PHP_SELF']);
switch($page_url) {
case '/mysite/home.php':
$page_title = "Home page";
print($page_title);
break;
}
?>
once again, thanks, Barry.
<?php
$page_url = ($_SERVER['PHP_SELF']);
switch($page_url) {
case '/mysite/home.php':
$page_title = "Home page";
print($page_title);
break;
}
?>
once again, thanks, Barry.