PHP to control CSS

Posted:
in General Discussion edited January 2014
I'm really getting into CSS for my webdesign and I love it so far (CSSEdit is very cool if you're just starting out, BTW). Now I want to take it a step further and allow my users to control their own CSS settings (like font size and color, etc). My first idea was to stick all these options in a sort of user control panel and save that information to a database along with their other personal stuff.



Is this doable? Can I have my PHP variables read into a CSS file and have it work? TIA.



-t

Comments

  • Reply 1 of 9
    I have no idea ... but would love to see some of your CSS designs.
  • Reply 2 of 9
    yes, its quite possible. make a function in php, that reads your db, grabs ur various css settings, formats it, then outputs it just like it would html. u can probably even make a separate css page which is served up by php (probably necessary to change the extension to .php or change apache setting to have php serve up .css pages).
  • Reply 3 of 9
    Totally possible.



    It is done by Moodle an online course CMS written in PHP, though not in any fancy way like you are proposing, just to sync up the CSS with colors defined in hard coded HTML styles as they transition from font tags et al to css.



    Check out:



    www.moodle.org



    and



    http://moodle.org/theme/moodle.org/styles.php



    and



    http://cvs.sourceforge.net/viewcvs.p...hp?view=markup



    -----



    Having said that, I would probably just define a few alternate stylesheets and use a javascript plus cookies style switcher (like the one Zeldman.com uses) for most purposes.



    http://www.zeldman.com/about/switch/



    -----



    Final note: Safari is a touch overzealous about caching, especially stylesheets so some handcoders update the stylesheet name every time they make a change e.g. style1234.css -> style1235.css so that Safari knows it is a new file and doesn't just reuse the stale cached copy.



    If you expect people to change their styles you may need to implement something like this for Safari users to see the changes without forcing a refresh.



    There's some info here (though it intends to force a refresh every time which isn't what you want)



    http://www.hivelogic.com/304.php
  • Reply 4 of 9
    torifiletorifile Posts: 4,024member
    Quote:

    Originally posted by thuh Freak

    yes, its quite possible. make a function in php, that reads your db, grabs ur various css settings, formats it, then outputs it just like it would html. u can probably even make a separate css page which is served up by php (probably necessary to change the extension to .php or change apache setting to have php serve up .css pages).



    Hmm, that's an interesting proposition. I was hoping to have a linked stylesheet and for some reason I always assumed it had to be a .css file. But maybe not... Lemme think about what I can do with this.



    cool gut: I'm still working on it. I'll post the site when our server gets in.



    stupider: I've thought about the cookie route, but my ultimate objective is to get the site to the point where it's no longer stateless. If they log in, it's just how they left it, where they left it and everything. Just some fun ideas I've been working on.
  • Reply 5 of 9
    cubedudecubedude Posts: 1,556member
    Does anyone know how GeekLog handles its themes? You might be able to adapt the code to what you need.



    http://www.geeklog.net/
  • Reply 6 of 9
    torifiletorifile Posts: 4,024member
    Quote:

    Originally posted by CubeDude

    Does anyone know how GeekLog handles its themes? You might be able to adapt the code to what you need.



    http://www.geeklog.net/




    AFAIK, geeklog uses specific stylesheets picked by the user. Something similar is what I'm after, but I'm lazy and prefer not to have to define them all first.
  • Reply 7 of 9
    Quote:

    Originally posted by torifile

    Hmm, that's an interesting proposition. I was hoping to have a linked stylesheet and for some reason I always assumed it had to be a .css file. But maybe not... Lemme think about what I can do with this.



    i haven't tried it (i dont do too much web php stuff), but i would imagine that the style sheet can be anything fed by the web server.
  • Reply 8 of 9
    Quote:

    Originally posted by torifile

    Hmm, that's an interesting proposition. I was hoping to have a linked stylesheet and for some reason I always assumed it had to be a .css file. But maybe not... Lemme think about what I can do with this.



    cool gut: I'm still working on it. I'll post the site when our server gets in.



    stupider: I've thought about the cookie route, but my ultimate objective is to get the site to the point where it's no longer stateless. If they log in, it's just how they left it, where they left it and everything. Just some fun ideas I've been working on.




    You can use PHP to include any kind of file - no matter what the extension - so you wouldn't need to change the default Apache config... It wouldn't be serving(parsing) that page, it would just be including it.



    I can't think of any way to get your site completely 'stateless' without using cookies. You could either store everything in the cookie, or you could store just the userID in the cookie and keep the other info either in a DB or in a flat file.



    You wouldn't have to make up complete independent style sheets and link them separately - you could have PHP output an inline style sheet as the page gets parsed by reading the person's cookie. I don't have a whole lot of CSS experience besides for formatting text, but runtime dynamic output is what PHP is all about...
  • Reply 9 of 9
    Pie man: I'm trying to avoid using cookies because if the user is not at that particular computer, they've got to deal with not having their settings. If I use a db to store their info and use that db information to render their view experience, it'll seem much less stateless. The only thing they would have to do would be to log in and they are right where they left things.



    Thanks for the input.
Sign In or Register to comment.