Hi, any one can please tell me how can i change CSS link using external php basically I am trying to change the link to my style sheet in the head of my index, by using an external php page with dropdown menu. Let's say someone selects "Style 3 - Green" from the dropdown and it automatically changes the link in the index to "style_green.css", is this possible, without using databases? I am trying to allow the user to select various css files without manually changing links in the index.
Hmm, maybe include will suffice? if (style == 3) include 'style_green.css'; else .. etc etc; Code (markup):
if you want to make it changed when the user select the style, you need to use java script. You have to reload the page to change the style, so you can do this by sending a form to the same page, or to use session, thats gets the user choise. Any way, put your <style> tag into a php var and then echo it: if($_POST['style'] == 1){ echo '<style type="text/css" media="screen">@import url(style1.css);</style>'; }else{ echo '<style type="text/css" media="screen">@import url(style2.css);</style>'; } PHP: hope it helps...
Instead of wrapping it inline set your headers to output css so it can be cached by the browser. header('Content-Type: text/css; charset: UTF-8'); header('Cache-Control: must-revalidate'); $expire_offset = 3600; // expires in 1 hour header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expire_offset) . ' GMT'); Code (markup): Also, you can use javascript to change the css without reloading the page, <link id="css" href="mycss.php?number=1" type="text/css" rel="stylesheet"> Code (markup): And then for your javascript event that is fired when the css is changed document.getElementById('css').href = 'mycss.php?number=2'; Code (markup): You'd also want to store the new css selected in a cookie (or a session when the mycss.php file is hit) so you can output the newly selected style on each subsequent page load.