02-18-2008, 07:12 PM
|
#10 (permalink)
|
|
The Acquainted
Join Date: Sep 2007
Posts: 126
Thanks: 4
|
Quote:
Originally Posted by ReSpawN
Thanks alot your guys, doin' my best huh. Learned a lot from it once again.
Got a good question for you guys tho. Sometimes, when a <link rel...> stylesheet is called uppon, the end of the url to the css is somewhat like this; ...style.css?v=1. How can you make css dynamic like that? 
|
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" />
|
|
|
|