Need instruction. Please.
Situation: Most of my site pages start with the following:

<?
include("include/common.inc.php");
top();
left();
middle();
bottom();
function middle(){
?>

My include/common.inc has the head, title, meta tags which means they look the same on EVERY single page of my site (hundreds of pages!). Not good for SEO.

Extract from include/common.inc:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>This is just a quick show etc etc ……….</head>

Question: How do I safely move the <head> to each individual page so that I can customize the title and meta tags? I do not care how long it takes me. Where do I place the <head> on the pages, before <?, after, in between?

I tried to place the <head> at the top of each page and tried MANY other things, it does not work.

Note: I still need include/common.inc to be there since it holds lots of functions.

THANK YOU EVERYONE!!!!!!!!!!!!!

Natasha:icon_cheesygrin:

Dani AI

Generated

Good diagnosis by and nice to see get the titles working. Below are a few practical, low-risk improvements and troubleshooting notes so per-page head content stays safe and maintainable across hundreds of pages.

Keep markup rendering and page data separate. Instead of hardcoding the entire <head> in an include or sprinkling title/meta logic across files, have a single header-rendering function in your include file that accepts an options array. That keeps common.inc as the place that prints the DOCTYPE/html/head while each page only supplies small, per-page data (title, description, extras). Example pattern (put this in common.inc and call it from each page):

function render_head($opts = array()) {
  $defaults = array('title'=>'Site default','description'=>'Default desc','charset'=>'UTF-8','extras'=>'');
  $o = array_merge($defaults, $opts);
  $title = htmlspecialchars($o['title'], ENT_QUOTES, $o['charset']);
  $desc  = htmlspecialchars($o['description'], ENT_QUOTES, $o['charset']);
  echo "<!DOCTYPE html>\n<html>\n<head>\n";
  echo "<meta charset=\"{$o['charset']}\">\n";
  echo "<title>{$title}</title>\n";
  echo "<meta name=\"description\" content=\"{$desc}\">\n";
  echo $o['extras']."\n</head>\n";
}

On each page, set a small array with that page’s values, include common.inc, then call render_head($pageValues). This avoids sending output too early, keeps escaping consistent, and centralizes future changes (eg. adding Open Graph or canonical tags).

If you saw the “failed to open stream” error, it’s an include-path problem. Inside include files, use file-relative includes so paths resolve reliably, e.g.:

include_once dirname(__FILE__).'/site_functions.php';

(or __DIR__ . '/site_functions.php' on newer PHP). Also check file permissions and case sensitivity on Linux hosts.

SEO/formatting tips: use UTF‑8, keep titles unique and concise (roughly 50–60 chars), meta descriptions short and meaningful (~120–155 chars), add canonical links for duplicate content, and consider Open Graph/Twitter tags for social sharing. If the header is still printed by a function like top(), set the page data before calling that function so the renderer can use it.

Recommended Answers

All 6 Replies

For the title, do this in each file:

define ("PAGE_TITLE", "Title for the Page");

And in common.inc put something like:

<title><? echo PAGE_TITLE; ?></title>

For the Meta tags, you could put together an array on each page like follows:

$page_meta_tags[] .= '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />';
$page_meta_tags[] .= '<meta name="description" content="stuff here" />';

And then in common.inc

foreach($page_meta_tags as $value) {
  echo $value;
}

This may need adjusting for your application, just an idea..

Your idea seemed perfect so I tried it right away. Unfortunatly I get this error. Any suggestion?

Question: Where exactly do you place the "define" function on each page? Perhaps that is my problem.

Thanks.

Natasha

ERROR MESSAGE:
Warning: include(include/site_functions.php) [function.include]: failed to open stream: No such file or directory in /home/content/d/o/r/dornhosting/html/include/common.inc.php on line 15

Warning: include() [function.include]: Failed opening 'include/site_functions.php' for inclusion (include_path='.:/usr/local/php5/lib/php') in /home/content/d/o/r/dornhosting/html/include/common.inc.php on line 15

This is where I put the define function one the page

<?
include("include/common.inc.php");
define ("PAGE_TITLE", "Title for the Page");
top();
left();
middle();
bottom();
function middle(){
?>

It is working GREAT now for the titles.

I am not sure what went wrong the first time.

Regardless ... this was the best peice of information I ever got.

THANK YOU!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Edit:
Apparanty the below is irrelevant since you say it now works. :)

-----------------------------
Does the file include/site_functions.php exist?

Can you post line 15 from common.inc and a few lines before and after it since this seems to be the cause of the problem if the file does exist.

If the <head> is echoed in the top() function then it should work as you have it, if it is echoed automatically by the common.inc then you should define the title before including the file.

hi there
please i want a Quick answer please
i dont know how to make the headline of my webpage move from the right to left i need it by html code please thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.