Jump to content

Trying to set Webpage Title dynamically


TomTees

Recommended Posts

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

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).

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

 

 

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).

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');

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!  :D

 

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/

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.