02-20-2008, 09:34 AM
|
#19 (permalink)
|
|
The Frequenter
Join Date: Sep 2007
Posts: 360
Thanks: 24
|
Quote:
Originally Posted by Sam Granger
Ok, well, this is how I'd do it. I wrote this code up quickly, haven't been able to test so sorry if it doesn't work!!
style.php - this file checks the requested id and includes the right css file. Code can be editted quite easily, not sure where you want to get css data from but I just include css files from a folder called css. The files I include are style[idhere].css eg style1.css.
PHP Code:
<?php
/** * @author Sam Granger * @copyright 2008 */
header ('Content-type: text/css'); // Display page as css file!
$style = (int) $_GET['v']; // Lets make $style sql safe...
// now, you can include your css from sql, php or just include the file you want to. In this example its just a file include
include './css/style'.$style.'.css'; // if $style = 1, css file that is loaded would be called style1.css
?>
How, to get the php file to display as a css file, we need to do a mod rewrite using htaccess. So make a .htaccess file with the following:
Code:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^style.css$ style.php [L]
</IfModule>
Now, in your html include your "css file" in header eg:
HTML Code:
<link rel="stylesheet" href="style.css?v=1" media="screen" type="text/css" />
|
Sam, you can directly link to PHP file.
HTML Code:
<link rel="stylesheet" href="style.php?v=1" media="screen" type="text/css" />
The header function on the PHP file makes sure that content is parsed as text/css.
PHP Code:
header ('Content-type: text/css'); // Display page as css file!
That does it all. You don't need mod_rewrite unless you want to make it all pretty. 
__________________
Necessity is the mother of invention.
My blog
|
|
|
|