irn3rd Posted July 15, 2008 Share Posted July 15, 2008 Hello again, I have a few php files with my websites design and colouring in, like my top banner my links and my colour scheme, but is it possible to use php to switch between two design adn use a cookie so it can be remembered on the next page etc and when the user re-visits the site? Thanks again Ben. Link to comment https://forums.phpfreaks.com/topic/114866-multy-styles-with-php/ Share on other sites More sharing options...
ag3nt42 Posted July 15, 2008 Share Posted July 15, 2008 sure is ben.. on the file that you pull in your stylesheet.css file replace yourstyle.css with $yourstyle variable.. and then setup a function to place the designated stylesheet name into the "$yourstyle" variable. at the same time create a session variable or cookie that contains the style selected.. Link to comment https://forums.phpfreaks.com/topic/114866-multy-styles-with-php/#findComment-590686 Share on other sites More sharing options...
irn3rd Posted July 15, 2008 Author Share Posted July 15, 2008 Right i know what your saying its just getting to do it, I've only dealt with variables in URL strings in taking data from one page to another. My CSS for background and Text/links: <style type="text/css"> <!-- body { background-color: #0024FF; } a:link { text-decoration: none; color: #000000; } a:visited { text-decoration: none; color: #000000; } a:hover { text-decoration: underline; color: #FFFFFF; } a:active { text-decoration: none; } body,td,th { color: #FFFFFF; } --> </style> I use includes to bring it to the file i want for example: <?php include('includes/style.php') ?> I would like to do the multi change code in a drop down list, i know how to set the list up its just getting it to work i don't understand. I would be grateful for some help, I'm still learning and searching for tutorials etc I'm very greatful and if you have a website ill put it on my i know it aint much but its a little something for you for helping me. Thank you. Link to comment https://forums.phpfreaks.com/topic/114866-multy-styles-with-php/#findComment-590826 Share on other sites More sharing options...
ag3nt42 Posted July 15, 2008 Share Posted July 15, 2008 ok well it has alot to do with your website structure believe it or not.. if your site is setup like myne... I use an index.php file that ALL other site pages are included too. based on which page you select one of the includes is brought in that reflects that page.. example: (index.php) <?php require('header.php')//Just like include only the script will error if the file is missing.. //HERE WE WILL CHECK FOR WHICH PAGE THE USER SELECTED if(isset($_GET['page']))//THIS MEAN THE CODE BELOW WILL ONLY RUN IF $_GET['page'] is set.. { if($_GET['page']=='home')//IF USER SELECTS HOME PAGE { include('home.php');//INCLUDE HOME PAGE } } if you do your site this way.. you can do this for you stylesheet <?php session_start(); //NOW WHEN YOU LOGIN THE USER OR THE USER SELECTS THEIR STYLE, YOU"LL NEED TO SET A SESSION //VARIABLE HOLDING THE STYLE NAME ie..'Yourstyle.css' ///SELECT STYLE if(isset($_SESSION['style'])) { $style=$_SESSION['style']; //MAKE $STYLE EQUAL TO STYLE SELECTED echo("<link rel='stylesheet' type='text/css' src=' " . $style . " ' />"); //ECHO OUT THE HTML FOR THE STYLE SHEET TO USE } ///SELECT PAGE if(isset($_GET['page']))//THIS MEAN THE CODE BELOW WILL ONLY RUN IF $_GET['page'] is set.. { if($_GET['page']=='home')//IF USER SELECTS HOME PAGE { include('home.php');//INCLUDE HOME PAGE } } ?> Link to comment https://forums.phpfreaks.com/topic/114866-multy-styles-with-php/#findComment-590863 Share on other sites More sharing options...
irn3rd Posted July 16, 2008 Author Share Posted July 16, 2008 Hello ag3nt42, So i put the first box of code in my index page, and the second bow if i stick that in what? and if its more useful ill upload my indexpage with my style php file? if that saves you time instead of explaining? Sorry if i seem slow im still getting used to this. thanks again Link to comment https://forums.phpfreaks.com/topic/114866-multy-styles-with-php/#findComment-591398 Share on other sites More sharing options...
ag3nt42 Posted July 16, 2008 Share Posted July 16, 2008 yea post your index code.. really tho all you have to do is set a SESSION variable somewhere and then each page plug it into the stylesheet src.. if(USER SELECTS ThisStyle.css) $_SESSION['style']='ThisStyle.css'; $STYLE=$_SESSION['style']; echo("<link rel='stylesheet' type='text/css' src='".$STYLE."'"); if you do your index page like myne tho you won't have to put the above code on every page. Link to comment https://forums.phpfreaks.com/topic/114866-multy-styles-with-php/#findComment-591481 Share on other sites More sharing options...
irn3rd Posted July 17, 2008 Author Share Posted July 17, 2008 Ok, got my index up with my includes files, style.php has the colouring in it etc Thankyou for the help, so new Sorry for the long reply aswell [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/114866-multy-styles-with-php/#findComment-592448 Share on other sites More sharing options...
ag3nt42 Posted July 17, 2008 Share Posted July 17, 2008 ok so your going to set up your sessions and stylesheets in your header.php since that should be carried across all the pages.. create a selection box containg a list of all the different style sheets you have.. your html form for users selection: <?php //INTIALIZE VARIABLES $S_checked1=''; $S_checked2=''; $S_checked3=''; $S_checked4=''; echo(" <select name='style'> <option ".$S_checked1." value='style1.css'>Style 1</option> <option ".$S_checked2." value='style2.css'>Style 2</option> <option ".$S_checked3." value='style3.css'>Style 3</option> <option ".$S_checked4." value='style4.css'>Style 4</option> </select> "); ?> the php to process it: <?php //First COLLECT THE POST INFO if(!(isset($_POST['style']))) { $STYLE='';// IS NOT SET SO STYLE EQUALS NOTHING (or default style) } else { $STYLE=$_POST['style']; // IS SET SO STYLE EQUALS USERS CHOICE } echo("<link rel='stylesheet' type='text/css' src=' " . $STYLE . " ' "); //NOW WE RUN ANOTHER CHECK TO SEE WHICH ONE USER PICKED AND CHECK IT ON THE SELECTION DROP DOWN switch ($STYLE){ case "style1.css": $S_checked1="CHECKED"; break; case "style2.css": $S_checked2="CHECKED"; break; case "style3.css": $S_checked3="CHECKED"; break; case "style4.css": $S_checked4="CHECKED"; break; } ?> Link to comment https://forums.phpfreaks.com/topic/114866-multy-styles-with-php/#findComment-592470 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.