Jump to content
Larry Ullman's Book Forums

Chapter 3 Script 3.2 echo $page_title causes error for header() function

Recommended Posts

In chapter 3.2 the code was introduced:

<title><?php echo $page_title; ?></title>

Having now contructed a website based on this I'm having error now using the header() function such as redirecting and form submission.

Each page includes the header file and defines the page title:

// include the header file:
include ('../includes/my_header.inc.php');
// Create the page title:
$page_title = 'My Page Title'; //line #13

Whenever I use the header() now I get this error:

Warning: Cannot modify header information - headers already sent by (output started at /home/mydomain/public_html/includes/my_header.inc.php:13)

Is there a way round this or do I have to redesign the website?

Link to comment
Share on other sites

You will get that warning every time you try to use the header function after you've already echo'ed stuff in your code.

The code will have to be reorganized so that the header functions all come before any echo statements, then you should be fine.

Link to comment
Share on other sites

I'm aware why I'm getting the warning. Do you mean change my entire website as every page includes the header file and will therefore echo the page title.

For example remove the echo and hard code the <html> <title> tag?

If there is an example of how such as page should be structured I would be grateful for direction.

Link to comment
Share on other sites


  • Create New...