Reply to comment

css variables via php header()

At work we often need to host tons images from an alternative location, so as to not overwhelm our boxes with literally thousands of hits per second. This presents a small problem for the site that uses lots of css styling for background images. Since CSS currently doesn't support dynamic variables, a change to the alternative location url means changing lots of hardcoded paths. The question becomes, how do I pass in one value to my CSS document and echo it throughout, whereever an image call is made.

The solution is the PHP header function. Simply create a PHP document, whatever.php, and then at the top of your file include this..

<?php Header ("Content-type: text/css"); > 

At the server level, this function defines your document as a CSS document, and if included like a normal CSS document, your browser will interpret it as such. Now you can define variables at the top of the file and echo them throughout.

Reply

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.