Jump to content
Larry Ullman's Book Forums
guvna

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?

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...