Can I put this in my HTML <head>?
<link rel="stylesheet" href="http://site.com/some/php/script/userid/style.php" />
Basically, can I pass a user ID via a URI segment (or a GET variable) to a PHP script – which will still be validly treated as a stylesheet?
So, for example, if in my webapp a user has a custom CSS stylesheet for their page, I can just load it up dynamically in my controller by outputting this as the stylesheet URL – is this possible? I know the PHP part is certainly possible, but will this still be valid or fully browser/server compatible?
Thanks!
I am assuming you’re asking “will this work?” and not “is this valid HTML?” for that, See @Gordon’s answer.
If your PHP script outputs a
text/csscontent type and valid CSS, this will work fine.This header is necessary for FF to interpret the CSS. See here why.
It will be desirable to add some caching headers as well, otherwise the resource will probably be requested on every page load.
However…
If you need to output dynamic CSS, consider having a static style sheet (i.e. one that does not get interpreted by PHP) with all the generic stuff, and adding dynamic data in the document’s head:
this way, the CSS resource can remain a static file. It will not require starting a PHP process to get served. If your CSS parameters change from page to page, this will save you a HTTP request.