Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3230522
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:56:13+00:00 2026-05-17T16:56:13+00:00

thank you for viewing. My website includes the same header and footer for each

  • 0

thank you for viewing.

My website includes the same header and footer for each page using PHP.

I wanted a style sheet that only applied specifically for a certain page, so put the style in using the appropriate tag.

...<body><style type="text/css"> /* what ever */ </style></body>...

The style sheet is processed correctly in all browsers I tested, however it is not validated correctly by W3C because it’s located inside the body tag instead of the head.

My question is:
If I can’t put the style sheet in the body tag, what is the best way to include it? I can reference the style sheet in the PHP header, but I’d rather not have another HTTP Request for such a small file. How would you do it? What is the least sloppy way to do it? Although the style tag shouldn’t be in <body>, it is still processed correctly by browsers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T16:56:13+00:00Added an answer on May 17, 2026 at 4:56 pm

    The best way would be to use a MVC framework that buffers your view file, and allow tag to be dynamically added to the head before output.

    Here is a ultra simple way of doing it:

    index.php:

    <?php
    class Page {
        private static $head = array();
        private static $content = '';
        static function add_head($tag) {
            self::$head[] = $tag;
        }
        static function render_head() {
            foreach (self::$head as $tag) echo $tag;
        }
        static function render_content() {
            echo self::$content;
        }
        static function read_content($file) {
            ob_start();
            require $file;
            self::$content = ob_get_clean();
        }
        static function render_layout($file) {
            require $file;
        }
    }
    
    Page::read_content('view.php');
    Page::render_layout('layout.php');
    ?>
    

    layout.php:

    <html>
        <head><?php Page::render_head(); ?></head>
        <body>
            <div id="header"></div>
    
            <div id="content"><?php Page::render_content(); ?></div>
    
            <div id="footer"></div>
        </body>
    </html>
    

    view.php:

    <?php Page::add_head('<title>Hello World!</title>'); ?>
    <h1>Hello</h1>
    <p>World</p>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a website that lets people view rows in a table (each row
I now have it set up so that when people go to a thank
I'm working on a website with a large number of pages, and each one
I just tried viewing my website http://www.logmytime.de/ in Opera (version 10.50) it gives me
Are there any tools/websites/utilities for viewing a website in hex as it comes strait
I have a ASP.Net website that is failing on AJAX postbacks (both with ASP.Net
What is the SQL query to select all of the MSSQL Server's logins? Thank
SQL is not my forte, but I'm working on it - thank you for
Please let me know what architecture do VoIP applications use, P2P or Client-Server? Thank
Thanks for reading this. I am dynamically generating some data which includes a select

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.