Prev: Hi list --- justa simple question
Next: pecl install geoip doesnt work. Warning: opendir(/var/tmp/pear-build-root/install-geoip-1.0.7//var/www/pear): failed to open dir: No such file or directory in PEAR/Builder.php on line 188
From: David Mehler on 7 Feb 2010 23:20 Hello, I'm trying to set up a web site. This site has multiple stylesheets, one default stylesheet that should be used if the other is not chosen. The second is a high contrast stylesheet and can be selected by user's who need it. I'm also thinking of adding two more for smaller and larger font selections. My issue is I want the high contrast sheet to be used on all subsequent pages and on subsequent visits to the site by user's who have selected it. I thought of using php with this and cookies. I'm using php5 and would appreciate any suggestions, googling has shown some examples, but none are working. Thanks. Dave.
From: Paul M Foster on 7 Feb 2010 23:45 On Sun, Feb 07, 2010 at 11:20:18PM -0500, David Mehler wrote: > Hello, > I'm trying to set up a web site. This site has multiple stylesheets, > one default stylesheet that should be used if the other is not chosen. > The second is a high contrast stylesheet and can be selected by user's > who need it. I'm also thinking of adding two more for smaller and > larger font selections. My issue is I want the high contrast sheet to > be used on all subsequent pages and on subsequent visits to the site > by user's who have selected it. I thought of using php with this and > cookies. I'm using php5 and would appreciate any suggestions, googling > has shown some examples, but none are working. > Thanks. > Dave. There are two main PHP-centric solutions to this. First is cookies (as you described) and the second is using the $_SESSION global array. Doing this is relatively straightforward, so if it's not working for you, I see two possibilities: 1) You're not actually doing it right. 2) The users isn't pressing the "Reload" button after selecting the stylesheet. (My experience has been that simply redisplaying a page will not clear the cached CSS styles for that page. You must hit the "Reload" button. In fact, in some cases, like offices with caching webservers or proxies, an admin will have to be called in to clear the cache on the proxy/server as well.) You should be able to do something like this (I'm using SESSION variables because cookies are more complicated): <?php // Top of page session_start(); if ($_SESSION['stylesheet'] == 'enlarged_print') $css = 'enlarged_print.css'; else ... ?> <html> .... <link href="<?php echo $css; ?>" rel="stylesheet" type="text/css"/> .... </html> Paul -- Paul M. Foster
From: "TG" on 8 Feb 2010 00:43 You could use PHP and cookies (session variables are only useful until the browser is closed, so it's not as persistant as it sounds like you may want). You could also have a system where users log in and they can save their preferences on their user account settings. What you may also look into is using Javascript (which can also set and retrieve cookies) and with a good Javascript library like jQuery, it should be relatively easy to dynamically switch style sheets. Here's an example of a jQuery based stylesheet switcher: http://www.kelvinluck.com/assets/jquery/styleswitch/toggle.html Click the styles1, styles2 and styles3 links. Also, there are JS scripts for adjusting font size, so you may not need a completely different stylesheet. But it would mean having well designed HTML that will scale nicely with the font change. Or you could just have a different stylesheet, as you mentioned, so you know it will look exactly how you want. You can see an example of a font size JS here: http://www.joomla-beez.com/ Keep clicking the links in the upper right and you can continue to increase or decrease the size quite a bit, not just one step. I know this is a PHP list but I think a client side script may work better in this case. -TG ----- Original Message ----- From: David Mehler <dave.mehler(a)gmail.com> To: php-general(a)lists.php.net Date: Sun, 7 Feb 2010 23:20:18 -0500 Subject: [PHP] php selecting multiple stylesheets > Hello, > I'm trying to set up a web site. This site has multiple stylesheets, > one default stylesheet that should be used if the other is not chosen. > The second is a high contrast stylesheet and can be selected by user's > who need it. I'm also thinking of adding two more for smaller and > larger font selections. My issue is I want the high contrast sheet to > be used on all subsequent pages and on subsequent visits to the site > by user's who have selected it. I thought of using php with this and > cookies. I'm using php5 and would appreciate any suggestions, googling > has shown some examples, but none are working. > Thanks. > Dave. > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
From: Ashley Sheridan on 8 Feb 2010 03:10 On Sun, 2010-02-07 at 23:45 -0500, Paul M Foster wrote: > On Sun, Feb 07, 2010 at 11:20:18PM -0500, David Mehler wrote: > > > Hello, > > I'm trying to set up a web site. This site has multiple stylesheets, > > one default stylesheet that should be used if the other is not chosen. > > The second is a high contrast stylesheet and can be selected by user's > > who need it. I'm also thinking of adding two more for smaller and > > larger font selections. My issue is I want the high contrast sheet to > > be used on all subsequent pages and on subsequent visits to the site > > by user's who have selected it. I thought of using php with this and > > cookies. I'm using php5 and would appreciate any suggestions, googling > > has shown some examples, but none are working. > > Thanks. > > Dave. > > There are two main PHP-centric solutions to this. First is cookies (as > you described) and the second is using the $_SESSION global array. > > Doing this is relatively straightforward, so if it's not working for > you, I see two possibilities: 1) You're not actually doing it right. 2) > The users isn't pressing the "Reload" button after selecting the > stylesheet. (My experience has been that simply redisplaying a page will > not clear the cached CSS styles for that page. You must hit the "Reload" > button. In fact, in some cases, like offices with caching webservers or > proxies, an admin will have to be called in to clear the cache on the > proxy/server as well.) > > You should be able to do something like this (I'm using SESSION > variables because cookies are more complicated): > > <?php > // Top of page > session_start(); > > if ($_SESSION['stylesheet'] == 'enlarged_print') > $css = 'enlarged_print.css'; > else > ... > > ?> > <html> > ... > <link href="<?php echo $css; ?>" rel="stylesheet" type="text/css"/> > ... > </html> > > Paul > > -- > Paul M. Foster > I'm doing this on my own site, and it works like this: The stylesheets are output in <a> tags, so that a user can click on one to select a style, refreshing the page. In the header include, I check first to see if a new style was sent in the $_GET array, then the $_SESSION array, then finally to see if there is a stylesheet entry in the $_COOKIES array. If none is found, a default is assumed, and I write this value to both the $_SESSION and $_COOKIES array. By checking them in the order above, it lets a user pick a new one from a link, and will remember their choice throughout their current session and any subsequent visits to the site. As all the stylesheets are included in the pages with the correct <link> tags anyway, anyone with a compatible browser (Firefox, Opera, etc) can select the style from a drop menu directly in the browser, although it's better to use the links, as the browser doesn't remember the choice from page to page. Thanks, Ash http://www.ashleysheridan.co.uk
From: Stephan Ebelt on 8 Feb 2010 05:18
On Sun, Feb 07, 2010 at 11:20:18PM -0500, David Mehler wrote: > Hello, > I'm trying to set up a web site. This site has multiple stylesheets, > one default stylesheet that should be used if the other is not chosen. > The second is a high contrast stylesheet and can be selected by user's > who need it. I'm also thinking of adding two more for smaller and > larger font selections. My issue is I want the high contrast sheet to > be used on all subsequent pages and on subsequent visits to the site > by user's who have selected it. I thought of using php with this and > cookies. I'm using php5 and would appreciate any suggestions, googling > has shown some examples, but none are working. in CSS there is also the concept of 'alternate stylesheets' build in. A page can basically specify as many stylesheets as it wants where one is default and all others are 'alternate'. The browser will then offer menu entries for the user to choose from. Ie in firefox you can choose the style from the menu at: View -> Page Style -> ... Here's how it works in detail: http://www.w3.org/Style/Examples/007/alternatives (note that this site also has alternate styles available) PHP could be used to define the default style sheet on a per user/application setting basis... stephan |