homepage Welcome to WebmasterWorld Guest from 54.227.20.250
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
parsing .css as .php
getting css to parse as php
nisiwi

5+ Year Member



 
Msg#: 3165249 posted 5:36 pm on Nov 22, 2006 (gmt 0)

Hi,

Have read about the how to in your fantastic forums and have tried this myself, but not achieved the desired results

I would like the CSS for a site to be parsed as PHP

the output though seems to result as text or css so I get the contents of the sites code displayed in Firefox or a partial render in IE

you can see it here at <snip>

here is the basic overview of my setup - its hosted on a godaddy shared hosting server - sorry about the long post and thank you for reading this and considering your reply

the top level index.php files has 7 css includes - this should be done from an external top level css file – but as I was experiencing problems I moved everything to the top level php file to see if problem persisted - which it did

I have added <?php Header ("Content-type: text/css");?> to the top of each css file to make sure that its seen as a css file

the CSS style sheets are included like so

<?php
$tempdir = $mainframe->getTemplate();
$template1 = "" . $mosConfig_live_site . "/templates/" . $tempdir . "/css/layout_css.css";
$template2 = "" . $mosConfig_live_site . "/templates/" . $tempdir . "/css/customise_css.css";
$template3 = "" . $mosConfig_live_site . "/templates/" . $tempdir . "/css/rounded_boxes_side.css";
$template4 = "" . $mosConfig_live_site . "/templates/" . $tempdir . "/css/rounded_boxes_top.css";
$template5 = "" . $mosConfig_live_site . "/templates/" . $tempdir . "/css/rounded_boxes_bottom.css";
$template6 = "" . $mosConfig_live_site . "/templates/" . $tempdir . "/css/menus.css";
?>

<style type="text/css" media="screen">
<?php include $template1;?>
<?php include $template2;?>
<?php include $template3;?>
<?php include $template4;?>
<?php include $template5;?>
<?php include $template6;?>
</style>

.htaccess file contents

# Allows css files to be parsed like PHP

AddType application/x-httpd-php .css

Options FollowSymLinks

RewriteEngine On

RewriteCond %{REQUEST_URI} (/¦\.htm¦\.php¦\.html¦/[^.]*)$ [NC]

RewriteRule ^(content/¦component/) index.php

RewriteCond %{REQUEST_URI} ^(/component/option,com) [NC,OR]

RewriteCond %{REQUEST_URI} (/¦\.htm¦\.php¦\.html¦/[^.]*)$ [NC]

RewriteCond %{REQUEST_FILENAME}!-f

RewriteCond %{REQUEST_FILENAME}!-d

RewriteRule (.*) index.php

RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=¦\%3D) [OR]

RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]

RewriteCond %{QUERY_STRING} (\<¦%3C).*script.*(\>¦%3E) [NC,OR]

RewriteCond %{QUERY_STRING} GLOBALS(=¦\[¦\%[0-9A-Z]{0,2}) [OR]

RewriteCond %{QUERY_STRING} _REQUEST(=¦\[¦\%[0-9A-Z]{0,2})

RewriteRule ^(.*)$ index.php [F,L]

# Getting Rid of pdf Files

RewriteCond %{QUERY_STRING} ^option=com_content&do_pdf=

RewriteRule ^index2\.php$ - [G]

#

# Getting Rid of print preview Files

RewriteCond %{QUERY_STRING} ^option=content&task=view&id=

RewriteRule ^index2\.php$ - [G]

#

# Stop SE Indexed obsolete pages

redirect /index2.php?option=com_content&do_pdf=1&id=6/ http://www.example.com/404.php/

redirect /index2.php?option=com_content&do_pdf=1&id=1/ http://www.example.com/404.php/

redirect /index2.php?option=com_content&do_pdf=1&id=16/ http://www.example.com/404.php/

redirect /index2.php?option=com_content&do_pdf=1&id=2/ http://www.example.com/404.php/

redirect /index2.php?option=com_content&do_pdf=1&id=3/ http://www.example.com/404.php/

redirect /index2.php?option=com_content&do_pdf=1&id=9/ http://www.example.com/404.php/

redirect /index2.php?option=com_content&do_pdf=1&id=7/ http://www.example.com/404.php/

redirect /index2.php?option=com_content&do_pdf=1&id=1/ http://www.example.com/404.php/

redirect /index2.php?option=com_content&do_pdf=1&id=10/ http://www.example.com/404.php/

[edited by: encyclo at 5:46 pm (utc) on Nov. 22, 2006]
[edit reason] url removed and examplified, see forum charter [/edit]

 

BjarneDM

10+ Year Member



 
Msg#: 3165249 posted 10:15 am on Nov 27, 2006 (gmt 0)

The way you've set it up the <?php Header ("Content-type: text/css");?> don't get used. The header command has to be issued!before!any! html is output. And you output the <style> command before you include any of your css files. In fact, if the header command did get issued, your index.php file would get treated as css by the browser instead of html. The header command has no value as such to the php parser in regard as to how the file is treated - every file you include get's treated as plain html and parsed.

see
[php.net...]
[php.net...]
for further information.

You do have set things correctly up to get css files you include in your html code with <link rel="stylesheet" type="text/css" href="test.css"> treated with the php parser. And if you do include them with <link>, you'll have to have the header command as the very!very! first line in those files - otherwise they'll get an incorrect content-type.

I'll recommend an extension to Mozilla/Seamonkey/Firefox : Live HTTP Headers.
This extension allows you to see the communication between the browser and the server - including the content-type. Firefox strictly follows the content-type as issued by the server, while at least previous versions of IE had a tendency to ignore these and follow the file extension instead.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved