madspof Posted September 18, 2008 Share Posted September 18, 2008 Hi everyone i was just designing a website and was wondering if you could run php in a .css file is it possible ? Thanks before hand madspof Quote Link to comment https://forums.phpfreaks.com/topic/124788-can-you-have-php-in-a-css-file/ Share on other sites More sharing options...
dropfaith Posted September 18, 2008 Share Posted September 18, 2008 just put css in a php file the reads as css Use the header function: header('Content-type: text/css'); Then name include your css file: <link rel="stylesheet" href="css.php" /> Quote Link to comment https://forums.phpfreaks.com/topic/124788-can-you-have-php-in-a-css-file/#findComment-644596 Share on other sites More sharing options...
GingerRobot Posted September 18, 2008 Share Posted September 18, 2008 Well, not exactly. You could rename your css file with a PHP extension and have it echo out the css. However, you would then lose the benefit of allowing the browser to cache the css file which reduces bandwidth usage and load times. The real question is why would you want to? Quote Link to comment https://forums.phpfreaks.com/topic/124788-can-you-have-php-in-a-css-file/#findComment-644598 Share on other sites More sharing options...
dropfaith Posted September 18, 2008 Share Posted September 18, 2008 true the need for this is odd i havent seen a reason yet either but thats the only option i forsee if someone really wanted to do it Quote Link to comment https://forums.phpfreaks.com/topic/124788-can-you-have-php-in-a-css-file/#findComment-644600 Share on other sites More sharing options...
GingerRobot Posted September 18, 2008 Share Posted September 18, 2008 It's more than likely that a better solution would to have mutliple stylesheets and have PHP determine which stylesheet to load. Quote Link to comment https://forums.phpfreaks.com/topic/124788-can-you-have-php-in-a-css-file/#findComment-644603 Share on other sites More sharing options...
madspof Posted September 18, 2008 Author Share Posted September 18, 2008 Ah right it was just a general wonder if it was possible, am sure i could find a use for it somwhere lol anyway thanks guys Quote Link to comment https://forums.phpfreaks.com/topic/124788-can-you-have-php-in-a-css-file/#findComment-644605 Share on other sites More sharing options...
xoligy Posted September 18, 2008 Share Posted September 18, 2008 Yes it possible i found some code on the internet that interested me which was protecting the css file as a php file here is the site infact http://www.n1studios.net/tutorials/php/css-file-protection.html Quote Link to comment https://forums.phpfreaks.com/topic/124788-can-you-have-php-in-a-css-file/#findComment-644615 Share on other sites More sharing options...
dropfaith Posted September 18, 2008 Share Posted September 18, 2008 still has the down side gingerrobot mentioned on cache like the header option Quote Link to comment https://forums.phpfreaks.com/topic/124788-can-you-have-php-in-a-css-file/#findComment-644620 Share on other sites More sharing options...
xoligy Posted September 18, 2008 Share Posted September 18, 2008 caching dont really bother me, why would you want to? a little more security? imagine you spend hrs changing a layout to make it more personal then someone comes along and in 2 seconds copies the work you spent hours doing so they can have a design more or less the same only things they have possibly changed? the icons kinda sucks lol Quote Link to comment https://forums.phpfreaks.com/topic/124788-can-you-have-php-in-a-css-file/#findComment-644627 Share on other sites More sharing options...
dropfaith Posted September 18, 2008 Share Posted September 18, 2008 true but im sure theres ways around that without too much effort. Quote Link to comment https://forums.phpfreaks.com/topic/124788-can-you-have-php-in-a-css-file/#findComment-644631 Share on other sites More sharing options...
ranjuvs Posted September 18, 2008 Share Posted September 18, 2008 Actually there is an use for this. We could dynamically load properties from a config file. For changing the theme and all we could use this. Quote Link to comment https://forums.phpfreaks.com/topic/124788-can-you-have-php-in-a-css-file/#findComment-644641 Share on other sites More sharing options...
xoligy Posted September 18, 2008 Share Posted September 18, 2008 maybe there are ways around it if you know the name of the session i dunno lol i just like the fact if they try and view it they get a nice message Quote Link to comment https://forums.phpfreaks.com/topic/124788-can-you-have-php-in-a-css-file/#findComment-644647 Share on other sites More sharing options...
CroNiX Posted September 18, 2008 Share Posted September 18, 2008 Actually there is an use for this. We could dynamically load properties from a config file. For changing the theme and all we could use this. You can use javascript as well for adjusting properties Quote Link to comment https://forums.phpfreaks.com/topic/124788-can-you-have-php-in-a-css-file/#findComment-644793 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.