Jump to content


Photo

CSS and PHP


  • Please log in to reply
29 replies to this topic

#21 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 03 October 2006 - 09:34 PM

Have you tried placeing a

header("Content-type: text/css");

at the top of your css files?

Here is an article that is somewhat related to your question. This is manly geared towards using php to avoid Css Hacks. If I were you I would read some of the comments.

Good Luck,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#22 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 03 October 2006 - 09:45 PM

background:url(<?php root ?>/includes/teal.gif) repeat-x;
Short hand isn't safe
use <?php echo $root; ?>
if that's what you are trying to do, and he's right you didn't try passing the header.
It looks like your using some form of templating system.  It iwll probably work once you pass it that header, it won't work if you don't, that tells the browser that it's a css file.  It also has to be valid css, that hte php outputs.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#23 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 03 October 2006 - 09:48 PM

You could also place this in a htaccess to tell apache to parse css like php.

AddHandler application/x-httpd-php .css


This is what I do..

Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#24 steelmanronald06

steelmanronald06
  • Staff Alumni
  • Advanced Member
  • 2,004 posts
  • LocationOk

Posted 04 October 2006 - 01:47 AM

it is saved as .php, it has the header thing in it, and i even did businessmans suggestion. nothing nothing, and nothing. :(

#25 neylitalo

neylitalo
  • Staff Alumni
  • Advanced Member
  • 1,854 posts
  • LocationMichigan, USA

Posted 04 October 2006 - 02:09 AM

The PHP engine never sees that CSS file. The client's browser finds the file when it sees the <link> tag, and it never goes through the PHP engine - the client requests that file from apache, which delivers it just as it sees it.\

tomfmason's suggestion will almost work, but he's got a couple Apache directives and their syntax mixed up. The directives you would want to set would be either:

AddHandler x-httpd-php .css
or
AddType application/x-httpd-php .css

And you'll want to make sure that you set the variable $path in the CSS file - but since I think you're going for portability here, that doesn't make sense at all. It would make more sense to just hard-code it into the CSS file, since that's effectively what would be going on anyway.
http://nealylitalo.net - My personal website, and home of The Netizen's Journal.

#26 steelmanronald06

steelmanronald06
  • Staff Alumni
  • Advanced Member
  • 2,004 posts
  • LocationOk

Posted 04 October 2006 - 03:57 AM


And you'll want to make sure that you set the variable $path in the CSS file - but since I think you're going for portability here, that doesn't make sense at all. It would make more sense to just hard-code it into the CSS file, since that's effectively what would be going on anyway.


what?

#27 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 04 October 2006 - 04:29 AM

content.php
<?
$path = "folder1";
?>

rest of your html content
------------------------------------

css.php

#topnav  {
background:url(<?=$path;?>/includes/teal.gif) repeat-x;
padding-top:5px;
color:#fff;
}

Edit:  Sorry didn't see the second page of this thread... This post is semi irrelivent now...
Why doesn't anyone ever say hi, hey, or whad up world?

#28 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 04 October 2006 - 04:40 AM

AddHandler x-httpd-php .css
or
AddType application/x-httpd-php .css


LOL... Thanks for correcting that..

Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#29 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 04 October 2006 - 05:36 AM

Try using the one I gave on page 1, it should work if sessions work on your server.

#30 steelmanronald06

steelmanronald06
  • Staff Alumni
  • Advanced Member
  • 2,004 posts
  • LocationOk

Posted 04 October 2006 - 01:50 PM

i have it to where at the top of every file, path is defined (root in my case) and then it includes the overall_header. php which has the css (renamed to .php) in it.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users