Jump to content

How to use PHP in CSS


faraz

Recommended Posts

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 :)

Link to comment
Share on other sites

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. :)

  • Like 1
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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; }

Link to comment
Share on other sites

  • Administrators

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 :)

  • Like 1
Link to comment
Share on other sites

#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 ?

Link to comment
Share on other sites

#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)

Link to comment
Share on other sites

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.

Loading...
×
×
  • Create New...