Newb
Newb

Reputation: 678

CSS not working with PHP script:

Here is the code from my style.php script The objective: User should be able to select and input different options for the background color and font.

This code snippet with css and php is called stlye.php and is suppose to supply the variables to be used on my outputform.php script.

<?php header("Content-type: text/css"); 
$gray = "#333";
$dkgreen = "#008400";
?>
body {
background:<?=$gray?>;
color:<?=$dkgreen?>;
}

Here is part of the php script from outputform.php:

<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>
Your Output
</title>
<link rel="stylesheet" type="text/css"
 media="screen" href="style.php">

I am pretty sure that by using href="style.php" I should be able to see the default colors coming from style.php above:$dkgreen for font color and $gray for background being displayed on outputform.php;however, this is not the case.

What am I doing wrong, or what do I need to read to fix this?

Overall objective is to get the CSS variables to outputform.php where I can manipulate them...give the user options to choose the font color and background color.

It's 5:51AM and Google info is overwhelming and does not want to play nice with me, either that or I need to get sleep.

if ($tired == sleep)
{
 print "get more coffee";
}
else
{
print "code badly...yeah, I am going to sleep now...................";
}

Upvotes: 1

Views: 6738

Answers (4)

Frankie
Frankie

Reputation: 25165

is it a cache problem?

Load style.php by hand ie. http://yoursite.com/style.php, if it is valid css it's a cache problem. You can solve it by calling:

href="style.php?a=<?=microtime()?">

is it a css/php problem?

If you load style.php and it does not work or outputs something weird then you have a different problem and a different fix. Always try to break big things into tiny blocks when you're out problem hunting.

Hope you have a nice sleep! ;)

Upvotes: 1

Kip
Kip

Reputation: 109503

You could try changing the content-type header. Set this at the beginning of style.php:

header('Content-type: text/css');

Upvotes: 2

Nathan Kleyn
Nathan Kleyn

Reputation: 5143

Try switching the echo tags with standard opening tags with the echo construct; you may find the short hand echo tag is not enabled thanks to the short_open_tag setting

background:<?php echo $gray; ?>;
color:<?php echo $dkgreen; ?>;

Upvotes: 5

Daniel A. White
Daniel A. White

Reputation: 191058

Try putting a query string after style.css in the link tag.

<link rel="stylesheet" type="text/css"
 media="screen" href="style.php?v=1234">

Upvotes: 4

Related Questions