Google

Dynamic CSS Stylesheets with PHP Home


Dynamic CSS Stylesheets with PHP
14/03/2006 posted by Kevin S
This is a quick guide to creating dynamic stylesheets using PHP, that will change you html pages depending on the URL that is being visisted on your website.

If you use Apache to host multiple websites that have different domain names, you might waht to use the server alias to have them point to the same web directory, but you might also want to use a different CSS depending on the target.

The code fragment below shows how to do this in PHP using the server variable HTTP_HOST.

<html>
  <head>

    <?php
		
      $host = $_SERVER['HTTP_HOST'];
		
      if( $host == "first.yourdomain.com" )
      {
        print("<link href='stylesheet1.css' rel='stylesheet' type='text/css' />");	
      }
      else if( $host == "second.yourdomain.com" )
      {
        print("<link href='stylesheet2.css' rel='stylesheet' type='text/css' />");	
      }
      else
      {
        print("<link href='stylesheet.css' rel='stylesheet' type='text/css' />");	
      }
		
    ?>
	
  </head>

  <body>

    Your Content goes here.	
	
  </body>

</html>