TomTees Posted November 25, 2010 Share Posted November 25, 2010 I am trying to set the HTML Page Title dynamically, but this code from my book doesn't work... <title> <?php // Dynamically set Page Title. if (isset($page_title)){ echo $page_title; } else { // Default Page Title. echo 'Knowledge is Power: And It Pays To Know'; } ?> </title> What is wrong with it? (All I see is the code in the Webpage/Window Title...) TomTees Link to comment https://forums.phpfreaks.com/topic/219846-trying-to-set-webpage-title-dynamically/ Share on other sites More sharing options...
BLaZuRE Posted November 25, 2010 Share Posted November 25, 2010 Does your webpage end in .php? i.e. index.php, page.php, etc.? Is the PHP engine supplied to you? Are you using a 'free webhosting' website? If so, what company? Your code is correct, though I'm not a fan of your formatting (then again we each have our own style). Link to comment https://forums.phpfreaks.com/topic/219846-trying-to-set-webpage-title-dynamically/#findComment-1139644 Share on other sites More sharing options...
TomTees Posted November 25, 2010 Author Share Posted November 25, 2010 Does your webpage end in .php? i.e. index.php, page.php, etc.? Is the PHP engine supplied to you? Are you using a 'free webhosting' website? If so, what company? Your code is correct, though I'm not a fan of your formatting (then again we each have our own style). I am using NetBeans on my laptop. The author said to call the page "header.html" What is wrong with my formatting? TomTees Link to comment https://forums.phpfreaks.com/topic/219846-trying-to-set-webpage-title-dynamically/#findComment-1139645 Share on other sites More sharing options...
MrXHellboy Posted November 25, 2010 Share Posted November 25, 2010 PHP needs the php extension to work. Link to comment https://forums.phpfreaks.com/topic/219846-trying-to-set-webpage-title-dynamically/#findComment-1139646 Share on other sites More sharing options...
Pikachu2000 Posted November 25, 2010 Share Posted November 25, 2010 It either needs a file extension of .php, or you need to configure your webserver to have the php interpreter parse files with a .html extension (which doesn't happen by default). Link to comment https://forums.phpfreaks.com/topic/219846-trying-to-set-webpage-title-dynamically/#findComment-1139647 Share on other sites More sharing options...
BLaZuRE Posted November 25, 2010 Share Posted November 25, 2010 Well, there's your problem. You need a .php page in order for the php engine to recognize it's a page to be rendered by PHP. Change the extension from .html to .php and you'll see it in the title. Maybe your author was/is going to have the header as an include? i.e. have an index.php page and inside that page do include('header.php'); or include_once('header.php'); Link to comment https://forums.phpfreaks.com/topic/219846-trying-to-set-webpage-title-dynamically/#findComment-1139648 Share on other sites More sharing options...
TomTees Posted November 25, 2010 Author Share Posted November 25, 2010 Well, there's your problem. You need a .php page in order for the php engine to recognize it's a page to be rendered by PHP. Change the extension from .html to .php and you'll see it in the title. Maybe your author was/is going to have the header as an include? i.e. have an index.php page and inside that page do include('header.php'); or include_once('header.php'); Yeah, I figured that out while you guys were responding. I placed the code in test.php and it ran/looks fine. The author is indeed making me create a header.html file that will ultimately be included in a php file but I'm not that far in my book yet! Thanks, TomTees P.S. Feel free to answer this post if you know the answer... http://www.phpfreaks.com/forums/php-coding-help/help-setting-up-path-constants/ Link to comment https://forums.phpfreaks.com/topic/219846-trying-to-set-webpage-title-dynamically/#findComment-1139650 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.