include function in stylesheet

Discussion in 'HTML' started by Edwin van der Vaart, Sep 8, 2008.

  1. Is it possible to use a php include function in a stylesheet?
    --
    Edwin van der Vaart
    http://www.evandervaart.nl/ Edwin's persoonlijke web site
    Explicitly no permission given to Forum4Designers, onlinemarketingtoday,
    24help.info, issociate.de, velocityreviews, umailcampaign.com,
    gthelp.com, webfrustration.com, excip.com and many other to duplicate
    this post.
    Edwin van der Vaart, Sep 8, 2008
    #1
    1. Advertising

  2. Edwin van der Vaart

    Gusero Guest

    Edwin van der Vaart wrote:

    > Is it possible to use a php include function in a stylesheet?


    No, but it would be so nice if this were possible!
    Gusero, Sep 8, 2008
    #2
    1. Advertising

  3. Edwin van der Vaart wrote:

    > Is it possible to use a php include function in a stylesheet?


    Technically, no, it would not be a stylesheet. Just as you can't use php in
    html - but you can create a file that contains php commands and other
    content so that when processed by a php processor, it produces an html file.
    Similarly, if you can make your php processor handle a file containing php
    commands and css content, it might produce a css stylesheet.

    But why would specifically use an include command? After all, css itself
    contains an include feature, an @import construct at the start of a css
    stylesheet.

    Yucca
    Jukka K. Korpela, Sep 8, 2008
    #3
  4. Ed Mullen wrote:
    > Edwin van der Vaart wrote:
    >> Is it possible to use a php include function in a stylesheet?

    >
    > No.
    >
    > What are you trying to accomplish?

    I was trying to reduce the size of the file by removing some code from
    e.g. style.css and place the code in an other file e.g. nav.css.

    Stupid me.
    css Is a styling thingy and not a code like C++, Java, PHP, etc.
    That's why I can't use a php include function.

    Thanx for the answer.
    --
    Edwin van der Vaart
    http://www.evandervaart.nl/ Edwin's persoonlijke web site
    Explicitly no permission given to Forum4Designers, onlinemarketingtoday,
    24help.info, issociate.de, velocityreviews, umailcampaign.com,
    gthelp.com, webfrustration.com, excip.com and many other to duplicate
    this post.
    Edwin van der Vaart, Sep 8, 2008
    #4
  5. Edwin van der Vaart <> writes:

    > Is it possible to use a php include function in a stylesheet?


    I *highly* doubt that your server is configured to process .css files
    with PHP. But, a .php file can output CSS text, images, or any other
    media type you want it to output. All you have to do is use PHP's
    header() function to set the correct Content-type.

    sherm--

    --
    My blog: http://shermspace.blogspot.com
    Cocoa programming in Perl: http://camelbones.sourceforge.net
    Sherm Pendley, Sep 8, 2008
    #5
  6. Jukka K. Korpela wrote:
    > Edwin van der Vaart wrote:
    >
    >> Is it possible to use a php include function in a stylesheet?

    >
    > Technically, no, it would not be a stylesheet. Just as you can't use php
    > in html - but you can create a file that contains php commands and other
    > content so that when processed by a php processor, it produces an html
    > file. Similarly, if you can make your php processor handle a file
    > containing php commands and css content, it might produce a css stylesheet.


    That does do the trick.
    Make a php handler that produce css content.

    > But why would specifically use an include command? After all, css itself
    > contains an include feature, an @import construct at the start of a css
    > stylesheet.

    Thank you for the info, explanation and pointing to the @import construct.
    --
    Edwin van der Vaart
    http://www.evandervaart.nl/ Edwin's persoonlijke web site
    Explicitly no permission given to Forum4Designers, onlinemarketingtoday,
    24help.info, issociate.de, velocityreviews, umailcampaign.com,
    gthelp.com, webfrustration.com, excip.com and many other to duplicate
    this post.
    Edwin van der Vaart, Sep 8, 2008
    #6
  7. Edwin van der Vaart <> writes:

    > I was trying to reduce the size of the file by removing some code from
    > e.g. style.css and place the code in an other file e.g. nav.css.


    The common way to do that is to simply put multiple stylesheet links
    in one's HTML.

    > css Is a styling thingy and not a code like C++, Java, PHP, etc.
    > That's why I can't use a php include function.


    That doesn't make a bit of sense. The reason you can't put PHP code
    in a .css file is that your server isn't configured to process .css
    files with PHP. You can easily output CSS text, images, or any other
    content type from a .php file though.

    sherm--

    --
    My blog: http://shermspace.blogspot.com
    Cocoa programming in Perl: http://camelbones.sourceforge.net
    Sherm Pendley, Sep 8, 2008
    #7
  8. Sherm Pendley wrote:
    > Edwin van der Vaart <> writes:
    >
    >> Is it possible to use a php include function in a stylesheet?

    >
    > I *highly* doubt that your server is configured to process .css files
    > with PHP. But, a .php file can output CSS text, images, or any other
    > media type you want it to output. All you have to do is use PHP's
    > header() function to set the correct Content-type.

    Thank you for the info.
    --
    Edwin van der Vaart
    http://www.evandervaart.nl/ Edwin's persoonlijke web site
    Explicitly no permission given to Forum4Designers, onlinemarketingtoday,
    24help.info, issociate.de, velocityreviews, umailcampaign.com,
    gthelp.com, webfrustration.com, excip.com and many other to duplicate
    this post.
    Edwin van der Vaart, Sep 8, 2008
    #8
  9. Gazing into my crystal ball I observed Edwin van der Vaart
    <> writing in news:b1611$48c5738c$d55d1d7e$17319
    @news.chello.nl:

    > Is it possible to use a php include function in a stylesheet?


    As others have said, it is possible to create a PHP document on the server
    and serve it as text/css, but, the only problem with this is that the
    server has to compile the PHP document each time, which defeats the ability
    for a browser to cache the stylesheet.

    --
    Adrienne Boswell at Home
    Arbpen Web Site Design Services
    http://www.cavalcade-of-coding.info
    Please respond to the group so others can share
    Adrienne Boswell, Sep 8, 2008
    #9
  10. Sherm Pendley wrote:
    > Edwin van der Vaart <> writes:
    >
    >> I was trying to reduce the size of the file by removing some code from
    >> e.g. style.css and place the code in an other file e.g. nav.css.

    >
    > The common way to do that is to simply put multiple stylesheet links
    > in one's HTML.
    >
    >> css Is a styling thingy and not a code like C++, Java, PHP, etc.
    >> That's why I can't use a php include function.

    >
    > That doesn't make a bit of sense. The reason you can't put PHP code
    > in a .css file is that your server isn't configured to process .css
    > files with PHP. You can easily output CSS text, images, or any other
    > content type from a .php file though.

    Sorry, I said it wrong, but I know that php can give a content type as
    an output.

    Thanx for correcting me.
    --
    Edwin van der Vaart
    http://www.evandervaart.nl/ Edwin's persoonlijke web site
    Explicitly no permission given to Forum4Designers, onlinemarketingtoday,
    24help.info, issociate.de, velocityreviews, umailcampaign.com,
    gthelp.com, webfrustration.com, excip.com and many other to duplicate
    this post.
    Edwin van der Vaart, Sep 8, 2008
    #10
  11. Ed Mullen wrote:
    > Edwin van der Vaart wrote:
    >> Ed Mullen wrote:
    >>> Edwin van der Vaart wrote:
    >>>> Is it possible to use a php include function in a stylesheet?
    >>>
    >>> No.
    >>>
    >>> What are you trying to accomplish?

    >> I was trying to reduce the size of the file by removing some code from
    >> e.g. style.css and place the code in an other file e.g. nav.css.
    >>
    >> Stupid me.
    >> css Is a styling thingy and not a code like C++, Java, PHP, etc.
    >> That's why I can't use a php include function.

    >
    > But ... wait! All you have to do is link both files in your page
    > header. As in:
    >
    > <link href="/styles/one.css" rel="styleSheet" type="text/css">
    > <link href="/styles/two.css" rel="styleSheet" type="text/css">
    > <link href="/styles/three.css" rel="styleSheet" type="text/css">
    >
    > However, if all you're trying to do is reduce the total file size this
    > isn't going to help. All you'd be doing is splitting a file of "x" size
    > into three. And a+b+c=x. No matter how, the same amount of data is
    > still downloading. Although, it may be easier to manage if you break
    > things into smaller logical pieces that have distinct themes/purposes.
    > That certainly makes sense.

    That makes sense. Using link for some styling.
    Thanks.
    --
    Edwin van der Vaart
    http://www.evandervaart.nl/ Edwin's persoonlijke web site
    Explicitly no permission given to Forum4Designers, onlinemarketingtoday,
    24help.info, issociate.de, velocityreviews, umailcampaign.com,
    gthelp.com, webfrustration.com, excip.com and many other to duplicate
    this post.
    Edwin van der Vaart, Sep 8, 2008
    #11
  12. Edwin van der Vaart

    dorayme Guest

    In article <54bcf$48c582ec$d55d1d7e$>,
    Edwin van der Vaart <> wrote:

    > Ed Mullen wrote:

    ....
    > > All you have to do is link both files in your page
    > > header. As in:
    > >
    > > <link href="/styles/one.css" rel="styleSheet" type="text/css">
    > > <link href="/styles/two.css" rel="styleSheet" type="text/css">
    > > <link href="/styles/three.css" rel="styleSheet" type="text/css">
    > >
    > > ...Although, it may be easier to manage if you break
    > > things into smaller logical pieces that have distinct themes/purposes.
    > > That certainly makes sense.

    > That makes sense. Using link for some styling.


    Sometimes you might find it convenient, for example, to keep a sheet for
    all navigation related things...

    --
    dorayme
    dorayme, Sep 8, 2008
    #12
  13. Edwin van der Vaart

    Bergamot Guest

    Adrienne Boswell wrote:
    >
    > As others have said, it is possible to create a PHP document on the server
    > and serve it as text/css, but, the only problem with this is that the
    > server has to compile the PHP document each time, which defeats the ability
    > for a browser to cache the stylesheet.


    Set cache info in the PHP headers, too, then the browser can cache it.

    --
    Berg
    Bergamot, Sep 8, 2008
    #13
  14. Edwin van der Vaart

    Neredbojias Guest

    On 08 Sep 2008, Bergamot <> wrote:

    >
    > Adrienne Boswell wrote:
    >>
    >> As others have said, it is possible to create a PHP document on the
    >> server and serve it as text/css, but, the only problem with this is
    >> that the server has to compile the PHP document each time, which
    >> defeats the ability for a browser to cache the stylesheet.

    >
    > Set cache info in the PHP headers, too, then the browser can cache
    > it.


    But for this case the best way might be to do multiple links rel and use
    php to pick the ones you want for each page.

    --
    Neredbojias
    http://www.neredbojias.org/ http://www.neredbojias.net/
    Great Sights and Sounds
    http://adult.neredbojias.org/ (adult)
    Neredbojias, Sep 8, 2008
    #14
  15. Neredbojias wrote:
    > On 08 Sep 2008, Bergamot <> wrote:
    >
    >> Adrienne Boswell wrote:
    >>> As others have said, it is possible to create a PHP document on the
    >>> server and serve it as text/css, but, the only problem with this is
    >>> that the server has to compile the PHP document each time, which
    >>> defeats the ability for a browser to cache the stylesheet.

    >> Set cache info in the PHP headers, too, then the browser can cache
    >> it.

    >
    > But for this case the best way might be to do multiple links rel and use
    > php to pick the ones you want for each page.

    Hmmm. A php switch with stylesheet links.
    Sound interesting. I done that a long time ago for a website.

    Thanx, Neredbiojas.
    --
    Edwin van der Vaart
    http://www.evandervaart.nl/ Edwin's persoonlijke web site
    Explicitly no permission given to Forum4Designers, onlinemarketingtoday,
    24help.info, issociate.de, velocityreviews, umailcampaign.com,
    gthelp.com, webfrustration.com, excip.com and many other to duplicate
    this post.
    Edwin van der Vaart, Sep 9, 2008
    #15
  16. Edwin van der Vaart

    Nico Schuyt Guest

    Edwin van der Vaart wrote:
    > Neredbojias wrote:


    >> But for this case the best way might be to do multiple links rel and
    >> use php to pick the ones you want for each page.


    > Hmmm. A php switch with stylesheet links.
    > Sound interesting. I done that a long time ago for a website.


    Right! Something like
    <?php
    if ($_GET['style']=="special"){
    echo '<link href="/styles/special.css" rel="stylesheet"
    type="text/css">';
    }
    ?>

    --
    Nico
    Nico Schuyt, Sep 9, 2008
    #16
  17. Nico Schuyt wrote:
    > Edwin van der Vaart wrote:
    >> Neredbojias wrote:

    >
    >>> But for this case the best way might be to do multiple links rel and
    >>> use php to pick the ones you want for each page.

    >
    >> Hmmm. A php switch with stylesheet links.
    >> Sound interesting. I done that a long time ago for a website.

    >
    > Right! Something like
    > <?php
    > if ($_GET['style']=="special"){
    > echo '<link href="/styles/special.css" rel="stylesheet"
    > type="text/css">';
    > }
    > ?>

    Thanks for you reaction.
    I had use the following for a example rollover menu page:
    <?php
    $s = $_GET['style'];
    if (!($s)) { $s = 'style'; }
    ?>

    <link rel="stylesheet" type="text/css" <?php echo ' href="' . $s .
    '.css"'; ?> >

    Some where in the <body>
    <ul>
    <li><a href="index.php?style=vert#vertical">Vertical css
    rollover</a></li>
    <li><a href="index.php?style=hor#horizontal">Horizontal css
    rollover</a></li>
    <li><a href="index.php?style=vertunord#vertunorded">Vertical css
    rollover with an unorderd list elements</a></li>
    <li><a href="index.php?style=horunord#horunorded">Horizontal css
    rollover with an unorderd list elements</a></li>
    <li><a href="index.php#test1">This is a horizontal css rollover
    test</a></li>
    </ul>

    Or I could use e.g.:
    <?php
    $s = $_GET['sw1'];
    if (!($s)) { $s = 'sw1'; }
    ?>

    In switch.php
    <?php include("{$s}.php"); ?>

    In sw1.php
    <a href="switch.php?sw1=sw2">

    In sw2.php
    <a href="switch.php?sw2=sw1">
    --
    Edwin van der Vaart
    http://www.evandervaart.nl/ Edwin's persoonlijke web site
    Explicitly no permission given to Forum4Designers, onlinemarketingtoday,
    24help.info, issociate.de, velocityreviews, umailcampaign.com,
    gthelp.com, webfrustration.com, excip.com and many other to duplicate
    this post.
    Edwin van der Vaart, Sep 9, 2008
    #17
  18. Edwin van der Vaart wrote:
    > Nico Schuyt wrote:
    >> Edwin van der Vaart wrote:
    >>> Neredbojias wrote:

    >>
    >>>> But for this case the best way might be to do multiple links rel and
    >>>> use php to pick the ones you want for each page.

    >>
    >>> Hmmm. A php switch with stylesheet links.
    >>> Sound interesting. I done that a long time ago for a website.

    >>
    >> Right! Something like
    >> <?php
    >> if ($_GET['style']=="special"){
    >> echo '<link href="/styles/special.css" rel="stylesheet"
    >> type="text/css">';
    >> }
    >> ?>

    > Thanks for you reaction.
    > I had use the following for a example rollover menu page:
    > <?php
    > $s = $_GET['style'];
    > if (!($s)) { $s = 'style'; }
    > ?>
    >


    Call my paranoid, but I think prudent, but I would do a bit of
    validation on that parameter. Think about it, what if
    s$="bogus.css'><link rel='section' href='/etc/shadow' title='Steal your
    secrets'>"

    Same kind of oversight caused that MySpace style switcher script problem
    a couple of years ago. I still get evidence in my logs of bots looking
    for the injection vulnerability...


    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
    Jonathan N. Little, Sep 9, 2008
    #18
  19. Edwin van der Vaart

    Bergamot Guest

    Neredbojias wrote:
    > On 08 Sep 2008, Bergamot <> wrote:
    >> Adrienne Boswell wrote:
    >>>
    >>> As others have said, it is possible to create a PHP document on the
    >>> server and serve it as text/css, but, the only problem with this is
    >>> that the server has to compile the PHP document each time, which
    >>> defeats the ability for a browser to cache the stylesheet.

    >>
    >> Set cache info in the PHP headers, too, then the browser can cache
    >> it.

    >
    > But for this case the best way might be to do multiple links rel and use
    > php to pick the ones you want for each page.


    That would affect caching the HTML output, not the CSS output. 2
    separate files, cached independently of each other.

    --
    Berg
    Bergamot, Sep 9, 2008
    #19
  20. Jonathan N. Little wrote:
    > Edwin van der Vaart wrote:
    >> Nico Schuyt wrote:
    >>> Edwin van der Vaart wrote:
    >>>> Neredbojias wrote:
    >>>
    >>>>> But for this case the best way might be to do multiple links rel and
    >>>>> use php to pick the ones you want for each page.
    >>>
    >>>> Hmmm. A php switch with stylesheet links.
    >>>> Sound interesting. I done that a long time ago for a website.
    >>>
    >>> Right! Something like
    >>> <?php
    >>> if ($_GET['style']=="special"){
    >>> echo '<link href="/styles/special.css" rel="stylesheet"
    >>> type="text/css">';
    >>> }
    >>> ?>

    >> Thanks for you reaction.
    >> I had use the following for a example rollover menu page:
    >> <?php
    >> $s = $_GET['style'];
    >> if (!($s)) { $s = 'style'; }
    >> ?>
    >>

    >
    > Call my paranoid, but I think prudent, but I would do a bit of
    > validation on that parameter. Think about it, what if
    > s$="bogus.css'><link rel='section' href='/etc/shadow' title='Steal your
    > secrets'>"
    >
    > Same kind of oversight caused that MySpace style switcher script problem
    > a couple of years ago. I still get evidence in my logs of bots looking
    > for the injection vulnerability...

    The injection vulnerability is in the script. The outcome of the this
    script is e.g. http://www.foo.foo/index.php?style=vert#vertical
    You can put any thing after the "=". This is called URL injection.
    That's why most webhostings ban this script.

    Correct me if I'm wrong.

    Don't worry, the script is used for intranet and not for internet.
    --
    Edwin van der Vaart
    http://www.evandervaart.nl/ Edwin's persoonlijke web site
    Explicitly no permission given to Forum4Designers, onlinemarketingtoday,
    24help.info, issociate.de, velocityreviews, umailcampaign.com,
    gthelp.com, webfrustration.com, excip.com and many other to duplicate
    this post.
    Edwin van der Vaart, Sep 10, 2008
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?ISO-8859-1?Q?J=F8rn_Tommy_Kinder=E5s?=

    Stylesheet referanse i stylesheet

    =?ISO-8859-1?Q?J=F8rn_Tommy_Kinder=E5s?=, Jul 3, 2004, in forum: XML
    Replies:
    3
    Views:
    557
    =?ISO-8859-1?Q?J=F8rn_Tommy_Kinder=E5s?=
    Jul 4, 2004
  2. Steven An
    Replies:
    1
    Views:
    486
    Martin Honnen
    Nov 23, 2004
  3. David Blickstein
    Replies:
    3
    Views:
    1,019
    David Blickstein
    Aug 2, 2005
  4. David Blickstein
    Replies:
    14
    Views:
    6,297
    Harrie
    Oct 16, 2005
  5. Andreas Bogenberger
    Replies:
    3
    Views:
    858
    Andreas Bogenberger
    Feb 22, 2008
Loading...

Share This Page