include function in stylesheet

  • Thread starter Edwin van der Vaart
  • Start date
E

Edwin van der Vaart

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.
 
J

Jukka K. Korpela

Edwin said:
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
 
E

Edwin van der Vaart

Ed said:
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.
 
S

Sherm Pendley

Edwin van der Vaart said:
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--
 
E

Edwin van der Vaart

Jukka said:
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.
 
S

Sherm Pendley

Edwin van der Vaart said:
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--
 
E

Edwin van der Vaart

Sherm said:
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.
 
A

Adrienne Boswell

Gazing into my crystal ball I observed Edwin van der Vaart
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.
 
E

Edwin van der Vaart

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


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.
 
E

Edwin van der Vaart

Ed said:
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.
 
D

dorayme

Edwin van der Vaart said:
Ed Mullen wrote: ....
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...
 
B

Bergamot

Adrienne said:
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.
 
N

Neredbojias

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.
 
E

Edwin van der Vaart

Neredbojias said:
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.
 
N

Nico Schuyt

Edwin said:
Neredbojias wrote:
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">';
}
?>
 
E

Edwin van der Vaart

Nico said:
Edwin said:
Neredbojias wrote:
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.
 
J

Jonathan N. Little

Edwin said:
Nico said:
Edwin said:
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...
 
B

Bergamot

Neredbojias said:
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.
 
E

Edwin van der Vaart

Jonathan said:
Edwin said:
Nico said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top