How to use PHP in CSS

Hello

I want use php in style (CSS).

#topBanner { background: <?php
if(Auth::$userinfo->code == KLM)
echo '<img src="http:// ****** /dev/lib/skins/crystal/images/KLM.jpg"/>';
else
if(Auth::LoggedIn() == false);
echo '<img src="http:// ******* /dev/lib/skins/crystal/images/UPS.jpg"/>' ;
?>; width: 970px; height: 109px; }

please correct this code

Right, you need to make your css a .php file and add the following at the top:

<?php header("Content-type: text/css"); ?>

And here’s your code corrected:

#topBanner { background: <?php
if(Auth::$userinfo->code == KLM){
echo 'http:// ****** /dev/lib/skins/crystal/images/KLM.jpg';
}else{
echo 'http:// ******* /dev/lib/skins/crystal/images/UPS.jpg';
} ?>; width: 970px; height: 109px; }

You might need to put the airline code (KLM) in quote marks.

1 Like

Right, you need to make your css a .php file and add the following at the top:

<?php header("Content-type: text/css"); ?>

And here’s your code corrected:

#topBanner { background: <?php if(Auth::$userinfo->code == KLM){ echo 'http:// ****** /dev/lib/skins/crystal/images/KLM.jpg'; }else{ echo 'http:// ******* /dev/lib/skins/crystal/images/UPS.jpg'; } ?>; width: 970px; height: 109px; }

You might need to put the airline code (KLM) in quote marks.

Hi

<?php header("Content-type: text/css"); ?>

body { background: url(images/mainbg.jpg) repeat-x 0 0 #fff; color: #171717; 
font-family: "segoe ui", tahoma, arial,helvetica,clean,sans-serif; font-size: 12px; margin: 0; padding: 0; }

a { text-decoration: none; color: #0040FF; }

#body { width: 970px; margin: 0 auto; padding: 0 0 0 0; background: #ffffff; font-size: 12px; border-top: none; border-bottom: none; padding-bottom: 10px; }

h1 { color: #FF6633; }

h3 { background: url(images/h3.jpg) no-repeat left; height: 25px; font-size: 18px; padding-left: 28px; padding-bottom: 0px; margin-top: 10px; color: #FF6633; }

hr{ margin-top: 15px; height: 1px; border: none; border-bottom: solid 1px #999; }

#innerwrapper { width: 970px; background: #fff; float: right; }

#topBanner { background: <?php
if(Auth::$userinfo->code == KLM)
{
echo "http:// *********** /dev/lib/skins/crystal/images/KLM.jpg";
}
else
if(Auth::LoggedIn() == false)
{
echo "http:// ******** /dev/lib/skins/crystal/images/UPS.jpg";
} 
?>; width: 970px; height: 109px; }

this is correct ?

and file name is ab.php

You’ll want to change the last bit to this, else it’ll get confused if you’re logged in but aren’t in the airline KLM:

#topBanner { background: <?php
if(Auth::$userinfo->code == KLM)
{
echo "http:// *********** /dev/lib/skins/crystal/images/KLM.jpg";
}
else
{
echo "http:// ******** /dev/lib/skins/crystal/images/UPS.jpg";
} 
?>; width: 970px; height: 109px; }

The easier way would be this:

In your CSS file:

#topBanner { background: /* default for when not logged in */ }
#topBanner .klm { background: /* klm image */ }
#topBanner .ups { background: /* Ups */ }
/* etc, setup your classes, one class for each code */

Then in the template:

<?php
$class = strtolower(Auth::$userinfo->code);
?>

<div id="topBanner" class="<?php echo $class;?>">

Much cleaner

1 Like
#topBanner { background: url(images/topbanner.jpg) ;}
#topBanner .KLM { background: url(images/KLM.jpg) ;}
#topBanner .UPS { background: url(images/UPS.jpg) ;}

Template

<?php
$class = strtolower(Auth::$userinfo->code);
?>
<div id="topBanner" class="<?php echo $class;?>">

Need 2 more classes for template ?

Those code are correct ?

What do you mean? That should be about right

#topBanner { background: url(images/KLM2.jpg) ; width: 970px; height: 109px; }
#topBanner .UPS{ background: url(images/UPS.jpg) ; width: 970px; height: 109px; }
#topBanner .KLM{ background: url(images/KLM.jpg) ; width: 970px; height: 109px; }

This code only shown first image (KLM2.jpg)

Right, and you need to add the other part in the template, which sets the right CSS class