Hi there,

I am looking to allow a user to customise their webpage through the use of a form to change a CSS file.

Example:
1. A form asking for a colour hex format
2. #FF5A00 entered
3. Background of webpage changed to #FF5A00 colour

I have been trying to implement this without success. Any guidance on how to go about this would be fantastic.

[I'm quite new to PHP and CSS so apoligies if this thread is in wrong area or too vague]

Thanks,

-Richter.

    Richter,

    This is a little vague, however, you can do this with 3 scenarios:

    1) The user comes on to the webpage, it asks them the questions, and it sets the properties, you can use sessions to save the users preferences. NOTE: I don't recommend this way.

    2) Same as above, however you set a cookie, some people don't like cookies but its easier for a PHP Beginner to get the hang of verses Sessions. You set the cookie, the page reads the preferences, and does its work

    3) If you have a login based system you can do as above but save the preferences in the database.

    Each of the 3 routes have a different approach.. For the sake of learning I would recommend cookies.. if this is what you would like, I will post an example for you.

    big.nerd

      Thanks very much 🙂

      I'll try ellaborate on some issues.

      1. An admin will login to their admin section.
      2. They will be presented with a form for changing CSS values. Such as entering a hex value for background colours.
      3. The changes are processed.
      4. Once changes are made they will have to be global to all users, if cookies are used then only that user will appear to have a custom layout (I believe);
        The custom layout is needed to be seen by all users.

      I hope that helps somemore, im still learning 🙂

      I was thinking of another menthod a bit more concrete. An admin can upload their CSS file through a form "file" input. Which will read out the file contents in a textarea. Changes can be made and then saved. But perhaps this isnt practical.

      An example would be great thanks a lot 😃

      -Richter

        Richter,

        Having them upload their own CSS would definately be the best thing, because any other way would require every page to be a PHP file. If you have them upload the CSS file then you can even have .html files read it.

        I would recommend doing some reading on file handling, writing files on your system if not done carefully can sometimes have unforseen results.

        I would google uploading and writing files in PHP.

          I'm going to go with the idea of uploading CSS file.

          Thanks a bunch for the help 🙂

            You can very well link a php script as a css file. PHP script generating your CSS depending on values entered via an admin panel.
            You can also force apache to serve CSS extension files as PHP in a specific directory if you want the css actually named css.
            If you just want to change some predefined style colors you could split your css into 2 files, one static, one dynamic generated as explained above.
            Those 3 solutions above do not require all pages to be PHP.
            And finally, you could just generate the styles info in the header of your page.

              Have a read of this article at A List Apart. It tells you how to use php to switch CSS and refers to another article that does it with javascript.

              Now cookies are not easier than sessions and sessions are far more usefull so you should learn about them rather than cookies.

              Having users upload their own css file depends on them knowing how to write css properly. They will also need to know about all the elements and ids in your page and even when they do it is still too easy to make a mistake and break the page if you have any positioned elements etc.

              Best option is an edit page that presents only those css properties that they can safely edit, you can then validate the entries before saving them.

              No problem whatsoever in having every page be php, or just contain some php. All you need is a small function that detects and sets the css that you include in each page.

                Write a Reply...