Skip to content Skip to sidebar Skip to footer

Adding To My Code Prevents Css External Rules From Applying

I have a webpage that I am trying to validate with w3. It says I need to add to the page above the tag so I did. As a result, my CSS messed up. U

Solution 1:

That JS you have in your body is whacked, the syntax is all wrong. Also that PHP won't process if it's in a straight html file as it will not run through the php parser. I'd reckon that's your issue right there. PHP is a preprocessor that generates html, you cant just put it in an html file and have it run. Since it's in a script tag and in the head, it won't output in the body, but if you use inspector in whatever browser you're using, you'll see it in the script tag in the markup.

The reason the PHP is parsing without the doctype declaration, is I am assuming because whatever server you're running this code on is assuming it's a php file instead of html. If you want to deliver dynamic css via a php file, you could call the php file externally like you would a css file eg: mysite.com/style.php.

Don't forget that if you're delivering dynamic css to users, to practice proper sanitization prior, eg using CSS tidy or some other method of validation and escaping. Ideally if you can do so, do the escaping/sanitizing on save, rather than on delivery, to lower overhead on your server for every call as well as to speed up the delivery to the end user. However, that's somewhat irrelevant if you're caching the css anyways.

Style.php would look something like this.

echo header("Content-type: text/css");
header("Pragma: nocache");
header("Cache-Control: no-cache, must-revalidate");
header("Last-Modified: " . date("D, d M Y H:i:s") . " GMT");
echo$css_stuffz_goes_here;
exit // or die

Post a Comment for "Adding To My Code Prevents Css External Rules From Applying"