configure apache to recognize php in css files

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dmcconkey@yahoo.com

    #1

    configure apache to recognize php in css files

    Hi folks,

    I have a website with linked CSS files controlling layout, via LINK
    tags. In these linked CSS files, I need to create dynamic styles. This
    is a website of articles, and for every article type in the MySQL
    database, I need another style.

    ..article-type-0{color:red;}
    ..article-type-1{color:red;} etc.

    I could use PHP in the HTML head to write styles, but I'm using the
    media attribute of the LINK tag to control which styles go to which
    output devices. Therefore, I'd like to use PHP to author a linked CSS
    file.

    Being an idiot, I had figured I could update my httpd.conf file (apache
    2/redhat 8) and rewrite an AddType line to read:

    AddType application/x-httpd-php .php .htm .html .css

    It kind of worked. Almost. In fact, calling up the CSS in a browser
    window showed that PHP did take over when asked and wrote my
    article-type classes into the right places, using valid CSS.

    However, once I did that, the web pages displayed as though no CSS file
    were present.

    Which tweak to httpd.conf or php.ini do I need to get PHP function in a
    linked CSS file?

    Thanks,
    -Dan

  • Dani CS

    #2
    Re: configure apache to recognize php in css files

    dmcconkey@yahoo .com wrote:[color=blue]
    > Hi folks,
    >
    > I have a website with linked CSS files controlling layout, via LINK
    > tags. In these linked CSS files, I need to create dynamic styles. This
    > is a website of articles, and for every article type in the MySQL
    > database, I need another style.
    >
    > .article-type-0{color:red;}
    > .article-type-1{color:red;} etc.
    >
    > I could use PHP in the HTML head to write styles, but I'm using the
    > media attribute of the LINK tag to control which styles go to which
    > output devices. Therefore, I'd like to use PHP to author a linked CSS
    > file.
    >
    > Being an idiot, I had figured I could update my httpd.conf file (apache
    > 2/redhat 8) and rewrite an AddType line to read:
    >
    > AddType application/x-httpd-php .php .htm .html .css
    >
    > It kind of worked. Almost. In fact, calling up the CSS in a browser
    > window showed that PHP did take over when asked and wrote my
    > article-type classes into the right places, using valid CSS.
    >
    > However, once I did that, the web pages displayed as though no CSS file
    > were present.[/color]

    Maybe this works: Put

    <?php
    header("Content-Type: text/css");
    ?>

    at the top of every .css file, so that the browser knows that it's
    dealing with a CSS stylesheet.
    [color=blue]
    >
    > Which tweak to httpd.conf or php.ini do I need to get PHP function in a
    > linked CSS file?
    >
    > Thanks,
    > -Dan
    >[/color]

    Comment

    • dmcconkey@yahoo.com

      #3
      Re: configure apache to recognize php in css files


      Dani CS wrote:[color=blue]
      > dmcconkey@yahoo .com wrote:[color=green]
      > > Hi folks,
      > >
      > > I have a website with linked CSS files controlling layout, via LINK
      > > tags. In these linked CSS files, I need to create dynamic styles.[/color][/color]
      This[color=blue][color=green]
      > > is a website of articles, and for every article type in the MySQL
      > > database, I need another style.
      > >
      > > .article-type-0{color:red;}
      > > .article-type-1{color:red;} etc.
      > >
      > > I could use PHP in the HTML head to write styles, but I'm using the
      > > media attribute of the LINK tag to control which styles go to[/color][/color]
      which[color=blue][color=green]
      > > output devices. Therefore, I'd like to use PHP to author a linked[/color][/color]
      CSS[color=blue][color=green]
      > > file.
      > >
      > > Being an idiot, I had figured I could update my httpd.conf file[/color][/color]
      (apache[color=blue][color=green]
      > > 2/redhat 8) and rewrite an AddType line to read:
      > >
      > > AddType application/x-httpd-php .php .htm .html .css
      > >
      > > It kind of worked. Almost. In fact, calling up the CSS in a browser
      > > window showed that PHP did take over when asked and wrote my
      > > article-type classes into the right places, using valid CSS.
      > >
      > > However, once I did that, the web pages displayed as though no CSS[/color][/color]
      file[color=blue][color=green]
      > > were present.[/color]
      >
      > Maybe this works: Put
      >
      > <?php
      > header("Content-Type: text/css");
      > ?>
      >
      > at the top of every .css file, so that the browser knows that it's
      > dealing with a CSS stylesheet.
      >[color=green]
      > >
      > > Which tweak to httpd.conf or php.ini do I need to get PHP function[/color][/color]
      in a[color=blue][color=green]
      > > linked CSS file?
      > >
      > > Thanks,
      > > -Dan
      > >[/color][/color]

      That worked exceptionally well.

      Much appreciated,
      -Dan

      Comment

      Working...