When a user logs in, add a separate <link> element for that user. Href can point to a script that generates css for the user, for example customcss.php?userid=1234&version=2 *). The script needs to return everything that the user entered earlier. Since you attach it as a separate CSS file, the browser will always consider it as such and will never run any scripts. Any HTML or Javascript is simply considered invalid CSS.
Note, however, that there is no harm in this, including scripts, because they will only be run in the browser of a registered user, so they can only crack their own look at your site. If they want to add Javascript, they can still do it by writing their own browser plugins, so you wonโt open an opportunity that was not there before.
The main thing you need to worry about:
- Usability. What to do if the user makes a mistake and accidentally hides the Body element. How can they reset this?
- SQL injection. Regardless of what you do or do not allow, always make sure that your entrance is a reorganization.
- Php injection Do not execute custom content (eval). Someday.
- Hide user information. Add the code to url customcss.php so that other users canโt guess about the user ID in order to get an idea of โโthe settings of other users.
*) I added a version number to the CSS URL, which you should update in the database every time the user updates their CSS. If you do not, browsers will cache the old CSS and users will complain to you because their changes will not be visible.
Goleztrol
source share