Hello, Is there a way to set the page's title and some other meta tags after processing the page's body where the appropriate information will be (after db queries) I know that it can be done via javascript but this is not seo friendly, and it will fail if noscript. so it must be done server-side. The best way is php but my page structure is a full page that includes the main content with php include (pseudo frames). and because the main content is after the page's title, we cannot call the variable containing the page title before creating it. any suggestions please? Thanks.
You might want to try putting your codes in a variable. You can create your <body> by adding it's parts to the variable step by step(depending on how your script works). and at the end add your <head> part to it's beginning.
There are several ways you can do this. Like Sepehr said, you can do your processing first, saving info to variables like $meta[description], and $pageTitle etc... The insert them into your page like this: <?PHP $pageTitle = "Test Page Title"; #some other queries and operations ?> <html> <head> <title><?PHP echo $pageTitle; ?></title> </head> <body> <div>content</div> </body> </html> Code (markup): The other way, would be to use a templating system, like XTemplate (not sure if this is still around, since I haven't used it in a while), or Smarty (requires PEAR). This allows you to do all your processing first, then calling separate html files, abstracting your code from your design.
Projekt Gopher has it down pat. imho. I've recently been learning php myself and this is the fastest most efficient way I'm currently using.
You can use output buffering, and before you flush the buffer, go through and replace the <title></title> section by retrieving the buffer with ob_get_contents() then echoing that before discarding the buffer.