FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Dynamic User Customizable Sites. CSS + PHP = Awesome!





qqz
Just like you can use PHP to write HTML or Javascript, you can use it to write your CSS pages as well. This allows you to create dynamic CSS which can prove to be very useful.

Simply write out your CSS usng PHP with a command like echo or print. Then, in areas where you would put a value, like Arial, or 12px, or FF0000, use a PHP variable in its place. You can then, before this, put a value in this variable from a database, sessions, or anything really. You could even use it to give your site a completely random color, font, size scheme.

I am mainly posting this to give you all, who are interested in this type of thing, and idea of how dynamic layouts can be done and how you could let the user customize parts of the site.

However, if any of you wish I can post an example of what this would look like. I figure its pretty self explanitory to those that would use it.

Hope this gives you some ideas, have fun!
charliehk
Of course, an example will help us understand!
simplyw00x
charliehk wrote:
Of course, an example will help us understand!

Like maybe one found in 3 seconds on Google?
BlackSkad
charliehk wrote:
Of course, an example will help us understand!


Indeed, "to google" is the verb that is right here. Just a few well chosen keywords like "dynamic CSS tutorial with php" and you get this:
Result

Check the first link: "Dynamic CSS with PHP", I guess this can help you Wink
charliehk
thx a lot! I didn't know the keywords for searching... also, a bit lazy, I admit
snowboardalliance
That would be interesting to try. Well after I finish my layout and then the phpBB integration Rolling Eyes
gamo
qqz wrote:
Just like you can use PHP to write HTML or Javascript, you can use it to write your CSS pages as well. This allows you to create dynamic CSS which can prove to be very useful.

Simply write out your CSS usng PHP with a command like echo or print. Then, in areas where you would put a value, like Arial, or 12px, or FF0000, use a PHP variable in its place. You can then, before this, put a value in this variable from a database, sessions, or anything really. You could even use it to give your site a completely random color, font, size scheme.

I am mainly posting this to give you all, who are interested in this type of thing, and idea of how dynamic layouts can be done and how you could let the user customize parts of the site.

However, if any of you wish I can post an example of what this would look like. I figure its pretty self explanitory to those that would use it.

Hope this gives you some ideas, have fun!


But sometimes using CSS make me confused because my webpage run good in Firefox but not right in IE, and convertly, good in IE but not good in Firefox. I usually use CSS level 2. Please give me some advisements in design crossflatform webpage. Thank alot.
Grimboy
Try to minimise the amount of css 2.
spider
with php, and css,,, its technicly a flat file, so, by using fopen and such to work with flat files, you can use it as such. there are also css functions that can be used. you could also save your css file as a php file or text file and just include them.
what your talking about is making your css files easy to change by possibly using a form. save the information like bgcolor=#<? echo $bgcolor; ?> in your php script,, you need the info for the $bgcolor variable. so, you would save a text file, php file, or config file. and just include those two files...
ironyCurtain
It's funny how phrases like "Just Google it," come about.

I think Calvin & Hobbes said it best:

Quote:
Verbing words weirds language.
digibluez
you can also amazon it if you like...and in the future as i hate that microsux so much i will block all access from MSIE cleints to my website-if all would do that and keep the ie out of their page it would be a much happier place.No more saying:
I made a nice css website and it took me lot of time to make it like that,but when i switch to ie i see all is a BIG mess.Anyone know some hacks!

Darn it-IE should go to hell,i say.If you dont have firefox Bye BYe.
rohan2kool
Well, i'll give an example:

This is an example site to select the font and font size:
Code:

<html><head><title></title>
<style type="text/css">
<?php
     $font=$HTTP_POST_VARS['fnt']; //get the font entered
     $fontsize=$HTTP_POST_VARS['fntsz']; //get the font-size entered
     if($font==NULL) { //if font has not been entered, apply default settings
        $font="arial";
     }
     if($fontsize==NULL) { //if font-size has not been entered, apply default settings
        $fontsize=1;
     }
     $fontsize=$fontsize;
?>
body {
       font-family: <?php echo("$font");?>; //Apply the font
       font-size:<?php echo("$fontsize");?>; //Apply the font-size and also add to it 'pt' for CSS recognition
  }
</style>
</head>
<body>
 <p>This is a text trial</p> <!--Trial to check the style-->
 <form action="<?php echo("$PHP_SELF");?>" method="POST"> <!--Form -->
 <p>Choose your font: <input type="text" name="fnt" size="20"/></p>
 <p>Choose your font-size: <input type="text" name="fntsz" size="20"/></p>
 </form>
</body>


Hope this helps you. Remeber to name the file as 'font.php'
anhstar
CSS is something that any professional web programmer must know of, but I would not say "must use".

Like other persons have posted there are many advantages with CSS, it help you change the look of your website in seconds, reduce the size of your pages, etc. However, when a client ask you to build a website that would work and look the same in IE and Firefox, you may be in a big trouble. IE is old, very old and doesn't support many CSS's feature, while Firefox is up to date.
So the only way is to use the basic CSS that both browser support, and even that cause problems sometime.

So, the conclusion is, CSS is a great tool, but until Microsoft update IE, its a tool to be used with caution.
rohan2kool
somebody atleast give their opinion on my example. It took almost half an hour to make it.
Bondings
rohan2kool wrote:
somebody atleast give their opinion on my example. It took almost half an hour to make it.

It looks great, but are you sure that a css file may end in .php? I always thought it is only something.css, but I could be wrong.
dcshoes23
Bondings wrote:
rohan2kool wrote:
somebody atleast give their opinion on my example. It took almost half an hour to make it.

It looks great, but are you sure that a css file may end in .php? I always thought it is only something.css, but I could be wrong.


It's fine b/c it's not an actual css file, it's a php page that generates a webpage with css in it.
Harrowed
Write your own Include file.. Makes it so much easier..

Also the good thing about using PHP is it can be browser specific.. And would lower your Bandwidth usage etc..

But then again you can JUST as easily do so with a few checks then direct them to a CSS which is loaded once and cache'd to be used over and over again..

PHP output has a last updated time of the moment it's processed UNLESS you write the handling yourself.. (not that hard).
yule
qqz wrote:
Just like you can use PHP to write HTML or Javascript, you can use it to write your CSS pages as well. This allows you to create dynamic CSS which can prove to be very useful.

Simply write out your CSS usng PHP with a command like echo or print. Then, in areas where you would put a value, like Arial, or 12px, or FF0000, use a PHP variable in its place. You can then, before this, put a value in this variable from a database, sessions, or anything really. You could even use it to give your site a completely random color, font, size scheme.

I am mainly posting this to give you all, who are interested in this type of thing, and idea of how dynamic layouts can be done and how you could let the user customize parts of the site.

However, if any of you wish I can post an example of what this would look like. I figure its pretty self explanitory to those that would use it.

Hope this gives you some ideas, have fun!


CSS+PHP All very handy codes, hope that everybody has a good code that sends out and is shared with everybody, thank you.
Grimboy
Harrowed wrote:
lower your Bandwidth usage etc.


While increasing your CPU usage.
Simulator
I have to say it is handy, I use it a lot in my site
Xcelerate
I've been wanting to do that, but I didn't think you could include PHP files as a CSS, can you?
Simulator
Do you mean CSS as PHP?
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.