Norman Posted August 20, 2008 Share Posted August 20, 2008 Hello, I have an index.php and an header.php. I want to show a different title per page, then I have thought to include my header.php and there put this: <title><?php $title ?></title> .. and in my index.php put this: <?phpinclude 'header.php';$title = 'My Index Title'; ?> .. and so on for the other pages. But I get a 'undefinied variable' message. Why? Link to comment Share on other sites More sharing options...
boen_robot Posted August 20, 2008 Share Posted August 20, 2008 Define your variables before you include a file that uses them. In your case: <?php$title = 'My Index Title';include 'header.php'; ?> Link to comment Share on other sites More sharing options...
Norman Posted August 20, 2008 Author Share Posted August 20, 2008 Done. Now it doesn't reproduce anything. Link to comment Share on other sites More sharing options...
unplugged_web Posted August 20, 2008 Share Posted August 20, 2008 Done. Now it doesn't reproduce anything.I've often used this myself and have never had any problems, but in the header file I put<title><?php echo "Welcome to my site - ".$title; ?></title> then in every page after that add <?php $title = 'Contact'; include('header.php');?> Link to comment Share on other sites More sharing options...
Norman Posted August 20, 2008 Author Share Posted August 20, 2008 Ops, I was not using the echo. Excuse me and thanks! Link to comment Share on other sites More sharing options...
unplugged_web Posted August 20, 2008 Share Posted August 20, 2008 Ops, I was not using the echo. Excuse me and thanks!no probs Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.