yahooman123
04-03-2009, 03:39 AM
I have php enabled in CSS and external functions do not work,
This works:
background-color:#<? if ('a' == 'a') { echo 'ff0000'; }?>;
but this does not work:
background-color:#<? if(isset($check) && ($check== 'No')) { echo 'ff0000'; }?>;
The second one is using a function which is included from a separate file. What can I try? Thanks
abduraooft
04-03-2009, 09:16 AM
I have php enabled in CSS and external functions do not work, Provide some more information, so that we can assure that your setup is OK.
<? if ('a' == 'a') { echo 'ff0000'; }?>
If short open tag is disabled, the above will not work.
What's the purpose of that if statement?
timgolding
04-03-2009, 09:29 AM
have you tried echoing $check on its own?
Apostropartheid
04-03-2009, 04:01 PM
Isn't isset() redundant there in any case? Yeah, echoing $check on its own should give you an idea as to what's wrong.
yahooman123
04-03-2009, 04:39 PM
I added css handler in htaccess in the root, and added <?php header("Content-type: text/css"); ?> to the top of the .css file.
The a=a script was for testing purposes. It works fine because it does not require any external functions.
If I set a variable for example, $color = 'ff0000'; at the top of the css file, and then echo $color, it works as well. However my problem is when I declare the variable outside the css file, for example if $color is declared in index.php, but index.php includes the .css.
abduraooft
04-03-2009, 04:49 PM
If I set a variable for example, $color = 'ff0000'; at the top of the css file, and then echo $color, it works as well. However my problem is when I declare the variable outside the css file, for example if $color is declared in index.php, but index.php includes the .css.
The following should work.
In your php file, add
<?php
session_start();
$_SESSION['color']='lightblue';
?> at the top.
Then link this file to your CSS file like
<link href="style.css.php" rel="stylesheet" type="text/css" />
In your style.css.php file add
<?php
session_start();
header("Content-type: text/css");
if(isset($_SESSION['color']))
$color=$_SESSION['color'];
?>
body{
background:<?php echo $_SESSION['color']; ?>
}
Apostropartheid
04-03-2009, 04:52 PM
Um, try passing the variables into the link URI
index.php
<?php
header("Content-Type: text/html; charset=utf-8");
$color = "333";
$background = "999";
?>
<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="styles.php?<?php
if(isset($color)) {
echo "&color=$color";
}
if(isset($background)) {
echo "&background=$background";
}
?>" media="screen"/>
...
styles.php
<?php
header("Content-Type: text/css");
if(isset($_REQUEST['color'])) {
$color = $_REQUEST['color'];
} else {
$color = "fff" // default color if it's not requested by index.php
}
if(isset($_REQUEST['background'])) {
$background = $_REQUEST['background'];
} else {
$color = "333" // default value
}
?>
html {
color: <?php echo $color; ?>;
background: <?php echo $background; ?>
}
Abdura got there first with sessions, which is another way to do it. You can modify his to get a "default value" type setting too.