Old 22-06-2007, 18:56   #1 (permalink)
raptrex
Registered User
 
Join Date: Oct 2006
Posts: 12
php in css

could someone check my php code
the file name is css.php
PHP Code:
<?php
header
("Content-type: text/css");
if(
basename($_SERVER['PHP_SELF'], '.php') == 'index')
{
?>    
#left {
    width: 140px;
    float: left;
    }
    
#main {
    margin-left: 150px;
    }
  
#container {
    width: 100%;
    float: right;
    margin-left: -140px;
    }    
<?php
}

?>
and i include it in my php file like this
<link rel="stylesheet" type="text/css" href="style/css.php" />

the problem is, when im on the index.php, it doesnt show the above css
  Reply With Quote
Old 22-06-2007, 19:31   #2 (permalink)
bluesage
Senior Member
 
Join Date: Dec 2006
Location: Switzerland
Posts: 350
why dont you simply use a css file ? I cant see why you would want to complicate things by creating css using php.

I would simply add the following to your pages:

<link rel="stylesheet" type="text/css" href="style/css.css" />
__________________
www.benshu.ch // Evolving with Style

  Reply With Quote
Old 22-06-2007, 21:25   #3 (permalink)
pgo
i'm done, son
 
Join Date: Jan 2005
Posts: 12,262
Maybe he wants to do some Shaun Inman fancy style color changing or something. "CSS variables" style.
  Reply With Quote
Old 22-06-2007, 23:15   #4 (permalink)
d3mcfadden
Senior Member
 
d3mcfadden's Avatar
 
Join Date: Apr 2005
Location: -
Posts: 694
Send a message via AIM to d3mcfadden
Here's your problem:
Quote:
if(basename($_SERVER['PHP_SELF'], '.php') == 'index')
PHP_SELF is not index.php in this case, it is css.php. This is because you are not "including" the file into index.php you are bringing it in via a <link> therefore it is it's own script with it's PHP_SELF reflecting it's name.

Easiest solution I think would be to pass the basename to the css file via querystring.
HTML Code:
<link rel="stylesheet" type="text/css" href="style/css.php?base=BASENAME" />
Reality is, there is probably much better logic than this, I just don't know what you are trying to achieve.

Last edited by d3mcfadden : 23-06-2007 at 10:18.
  Reply With Quote
Old 26-06-2007, 07:01   #5 (permalink)
paulanthony
mingin dawg baitch
 
paulanthony's Avatar
 
Join Date: Apr 2004
Location: Belfast
Posts: 1,032
Send a message via MSN to paulanthony
I'm not a PHP coder, but maybe doing things inline also helps.

<?php
if(basename($_SERVER['PHP_SELF'], '.php') == 'index')
{
?>
<style type="text/css">
#left {
width: 140px;
float: left;
}

#main {
margin-left: 150px;
}

#container {
width: 100%;
float: right;
margin-left: -140px;
}
</style>
<?php
}

?>
__________________
  Reply With Quote
Old 26-06-2007, 07:10   #6 (permalink)
freelancr
Senior Member
 
freelancr's Avatar
 
Join Date: Oct 2006
Posts: 2,060
Just confused as to why you want to do this.
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8