Jump to content

[SOLVED] How to use PHP in embedded CSS?


Gleasonator

Recommended Posts

Hi all.

 

I have CSS embedded into a PHP page using style tags (it doesn't import a stylesheet, the style is right in the PHP file).

 

Here's what I have:

 

<?php

$stylepath = $_COOKIE['themepath']!='' ? $_COOKIE['themepath'] : 'darkgreen';
$phpbb_root_path = "/home/gleasona/public_html/forums/";
$t_theme_path = $phpbb_root_path . "styles/" . $stylepath . "/theme";

?>

<style type="text/css">

#wrap {
width: 910px;
background: #FFFFFF url("<?php echo "$t_theme_path"; ?>/images/bg_body.gif") repeat-y 0 0;
margin: 10px auto 0px;
text-align: left;
padding: 0;
}

</style>

 

The part I'm having trouble with is <?php echo "$t_theme_path"; ?>. Am I using that correctly? I want the server to parse that variable in the CSS; I want the server to see that line of code as background: #FFFFFF url("/home/gleasona/public_html/forums/styles/get_style_name_from_cookie/images/bg_body.gif") repeat-y 0 0;

 

Can anyone help?

 

Thank you.

 

-Alex

Link to comment
https://forums.phpfreaks.com/topic/106857-solved-how-to-use-php-in-embedded-css/
Share on other sites

"/home/gleasona/public_html/" this part is only used for server-side code. Since your echoing onto a client-side (CSS) you need to use client-side url links.

 

 

Hi Dat.

 

Thanks for your help, it's much appreciated. But I'm still having a bit of trouble here... maybe I'm not doing this right.

 

The  file posted above is in is root/wp-content/themes/ygo-black-magic-10/header.php

 

And $phpbb_root_path is root/forums

 

So should $phpbb_root_path = "/../../../forums/"; ?

 

I tried that and it wont grab the files I want from that folder.

 

EDIT: Never mind, I see the issue. I was trying to use "/../../../forums/" where the server side path was required. I made two seperate variables now; one for the server side path and one for the client side. Thanks very much. Solved.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.