spacepoet Posted February 10, 2011 Share Posted February 10, 2011 Hello: I am trying to make a StyleSheet updateable from my admin panel, but I'm not sure if what I want to do is possible. So ... I have a TEXTAREA in my admin panel that writes to the DB just fine. it has styles like: body { margin: 5px 0; padding: 0; background-color: #ebe9e6; background-image: url('../images/Site-BG2.jpg'); background-position: center bottom; background-repeat: no-repeat; background-attachment: scroll; font-family: arial, sans-serif; font-size: 100%; line-height: 1.4em; } ... Etc... On the frontend, it writes into the StyleSheet just fine like: <?php include('myConn.php'); //contains your mysql connection and table selection $query=mysql_query("SELECT * FROM myStyleSheet") or die("Could not get data from db: ".mysql_error()); while($result=mysql_fetch_array($query)) { $myPageData=$result['myPageData']; } ?> <?php echo $myPageData; ?> So, what I want to see is if I can somehow pull the styles onto the page like: <link rel="stylesheet" type="text/css" href="include/StyleSheet.css" /> Now, if I do it as listed above it and look at the code it displays the <?php include('myConn.php'); //contains your mysql connection and table selection Etc... If I do it like <link rel="stylesheet" type="text/css" href="include/StyleSheet.php" /> It displays the styles fine, but the browser doesn't read it as a StyleSheet and therefore the page doesn't get formatted. So, is there any way to make this work? Anyone have any ideas about this? The idea is so I can manage the Styles via an admin panel remotely without having to login with web editing software. Thanks. Link to comment https://forums.phpfreaks.com/topic/227313-dynamic-stylesheet-is-there-a-way-to-do-this/ Share on other sites More sharing options...
sirholiday Posted February 10, 2011 Share Posted February 10, 2011 Hi add header("Content-type: text/css"); to the top of the php page. also make sure that there is no space before <?php headers won't work unless nothing else has been outputted. Link to comment https://forums.phpfreaks.com/topic/227313-dynamic-stylesheet-is-there-a-way-to-do-this/#findComment-1172519 Share on other sites More sharing options...
acefirefighter Posted February 11, 2011 Share Posted February 11, 2011 I am working on something similar and I added this line to my .htaccess file so that I could avoid using the .php extension and instead I was able to use the .css extention to avoid any possible search engine conflicts. I am not really sure that there would be any but was trying to be safe. RewriteRule ^(.*)\.css$ $1\.php [L] Link to comment https://forums.phpfreaks.com/topic/227313-dynamic-stylesheet-is-there-a-way-to-do-this/#findComment-1172559 Share on other sites More sharing options...
spacepoet Posted February 11, 2011 Author Share Posted February 11, 2011 Hi there: Thanks to the both of you for the tips. I will try them out! Link to comment https://forums.phpfreaks.com/topic/227313-dynamic-stylesheet-is-there-a-way-to-do-this/#findComment-1172562 Share on other sites More sharing options...
spacepoet Posted February 11, 2011 Author Share Posted February 11, 2011 One quick follow-up: Will the header("Content-type: text/css"); Work in the same fashion for other files: .js, .txt, and .xml ?? Link to comment https://forums.phpfreaks.com/topic/227313-dynamic-stylesheet-is-there-a-way-to-do-this/#findComment-1172569 Share on other sites More sharing options...
acefirefighter Posted February 11, 2011 Share Posted February 11, 2011 I found a couple of links for you... http://www.javascriptkit.com/javatutors/externalphp.shtml http://www.satya-weblog.com/2008/02/header-for-xml-content-in-php-file.html http://stackoverflow.com/questions/1414325/is-headercontent-typetext-plain-necessary-at-all Link to comment https://forums.phpfreaks.com/topic/227313-dynamic-stylesheet-is-there-a-way-to-do-this/#findComment-1172576 Share on other sites More sharing options...
spacepoet Posted February 11, 2011 Author Share Posted February 11, 2011 Excellent! Thank you much! Link to comment https://forums.phpfreaks.com/topic/227313-dynamic-stylesheet-is-there-a-way-to-do-this/#findComment-1172593 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.