PHP for CSS colours - Simple variables not working
Posted by: jmcdonnell (---.124.broadband7.iol.cz)
Date: November 09, 2007 08:37PM

Hi all,
This is my first post on here, so thanks in advance for reading it winking smiley

I am pretty new to PHP, but comfortable with programming techniques (mainly in AS2).

I am trying to set up this example to use variables for colours in my CSS:
[www.barelyfitz.com]
(a great concept).

Somehow when testing locally the variables are not being saved, and the css class is not being applied correctly:

This is the CSS (php) code in CSS/style.php:
<?php

header("Content-type: text/css"winking smiley;

$boldHeader = '#191b70';
$contentBG = '#ececec';
$subHeader = '#60b30b';
$pageBG = '#2e2e2e';
$bodyText = '#2e2e2e';
$attnColour = '#fe3600';
?>


#wrap
{
background-color:<?=$boldHeader?>;
}

and the CSS file is included in the page as follows:
<link href="CSS/style.php" rel="stylesheet" type="text/css" media="screen"/>

When I upload it to my webspace (jm3d.co.uk) it works fine and the background colour is applied to <div id='wrap'></div> as expected, but under my WAMP5 1.7.3 install this does not work.

If I run this:
<?php
phpinfo();
?>

all appears to be working fine, and in other scripts I have written, variables are working perfectly, but not this one ;(

As I said, it is working on my webspace:
[www.jm3d.co.uk]

but not locally.

Anyone any ideas?

Thanks a bunch ;l)

Jamie



Post Edited (11-09-07 20:37)

The world is big, the web is bigger winking smiley

Options: ReplyQuote
Re: PHP for CSS colours - Simple variables not working
Posted by: toivo (203.19.130.---)
Date: November 09, 2007 11:32PM

Hi,

Unless you have changed the default setting in php.ini:

short_open_tag = Off

your short open tag <? should be changed to <?php for the script to work. The default in PHP 5 for short open tags is off, but some scripts still use the short version.

If you decide to modify the php.ini file, make sure your modify the one in the Apache folder:
c:\wamp\apache2\bin

The other php.ini file in c:\wamp\php controls the command line scripts.

Regards,



toivo
Sydney, Australia

Options: ReplyQuote
Re: PHP for CSS colours - Simple variables not working
Posted by: jw_k (---.net-you.de)
Date: November 09, 2007 11:48PM

with short_open_tag = Off it's not enough to replace <? with <?php , but you have to modify segments like

h1 {
color:<?=$dkgray?>
}

with

h1 {
color:<?php echo $dkgray;?>
}

or - what I prefer - :

echo "
/* other segments here */
h1 {
color: $dkgray
}
/* other segments here */
";

ymmv

Options: ReplyQuote
Re: PHP for CSS colours - Simple variables not working
Posted by: jmcdonnell (---.124.broadband7.iol.cz)
Date: November 10, 2007 11:41AM

Awsome, thanks for you're help guys - I have switched short_open_tag = on as this is the same on my web server. Does this have any security implications I should know about? Or is it just the ue of using <?xml ?> inline that I need to watch out for?

And I presume the long form <?php ... ?> will still work just fine?

Thanks both for taking the time to answer winking smiley

Regards

Jamie



The world is big, the web is bigger winking smiley

Options: ReplyQuote


Sorry, only registered users may post in this forum.