Jump to content

Can I embed php variables in an external css?


paddyhaig

Recommended Posts

I have embedded a couple of variables in an external css. One of them works the others do not. The mapping to the background_image works fine, however the #color definitions do not. Any thoughts greatly appreciated.

Here is a clip from the external css.

At the top of the css I have a php include that has the color rules.

 

body {
background-repeat: no-repeat;
background-color: <?php echo $body_background_color ?>;
}
#backdrop {
position:absolute;
width:970px;
height:985px;
z-index:0;
left:50%;
top: -1px;
margin-left:-485px;
background-image: url(../../graphics/<?php echo $_background_image ?>); 
}

 

 

Link to comment
Share on other sites

Actually the mapping to the background_image works does not work, seems I had 2 background image mappings.

What I am trying to do is create a way that the user can make certain customization to the css unique to their specific account.

When they log into their account they can apply unique rules. Although the majority of the rules are static.

Link to comment
Share on other sites

I tried to save them with the .php extension as opposed to the css ~ with not a lot of luck. I will try again, maybe I screwed something up. There's nothing I can do with the server unless it's a matter of introducing a .htaccess file. The site is with a paid hosting service. Thanks however for your input.

Link to comment
Share on other sites

Does anyone know what method is used on other large php css projects for introducing specific account customizations. I am sure cookies are involved. For example, you log into your web based email and you can change the layout to your own specific likes. I have also introduced other languages, although I am not sure if I am using a standard method?

Link to comment
Share on other sites

Lots of ways it could be done, probably the simplest though is too simply store key => value pairs against a users id. So... you'd need a table.

 

CREATE TABLE custom_settings (
  id INT NOT NULL AUTO_INCREMENT, 
  PRIMARY KEY(id),
  user_id INT,
  k VARCHAR(80),
  v VARCHAR(80)
);

 

Then, for say user 'thorpe' whos id is 19232, we store some settings.

 

INSERT INTO custom_settings (k, v) VALUES ('text-color', '#fff');
INSERT INTO custom_settings (k, v) VALUES ('background-color', '#666');
INSERT INTO custom_settings (k, v) VALUES ('max-post-per-page', '20');

 

Then, when a user logs in you grab those settings and store them along with there session.

 

// login code goes here.

if ($result = mysql_query("SELECT k, v FROM custom_settings WHERE user_id = 19232")) {
  if (mysql_num_rows($result)) {
    while ($row = mysql_fetch_assoc($result)) {
      list($k, $v) = $row;
      $_SESSION['custom_settings'][$k] = $v;
    }
  }
}

 

You can now use....

 

<?php echo $_SESSION['custom_settings']['background-color']; ?>

 

wherever you need it and it will be custom for the logged in user.

 

Of course the top few queries also need to be executed via php but that should be pretty simple to figure out.

Link to comment
Share on other sites

There's a pretty major floor in the INSERT statements. I forgot, you'll need to put the user_id in there too.

 

INSERT INTO custom_settings (user_id, k, v) VALUES (19232, 'text-color', '#fff');
INSERT INTO custom_settings (user_id, k, v) VALUES (19232, 'background-color', '#666');
INSERT INTO custom_settings (user_id, k, v) VALUES (19232, 'max-post-per-page', '20');

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.