![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Aug 2006
Posts: 11
Rep Power: 0
![]() |
Ok, so not everyone has the same monitor and not everyone has 20-20 vision. So, since the "Ctrl++" trick is not well known you have to make a font size chooser for your site. So here is what I have done:
stylesheets.php: [PHP]<?php $ref = (isset($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : "http://{$_SERVER['SERVER_NAME']}/"; if ((isset($_GET['stylesheet'])) && (strlen($_GET['stylesheet']) < 20)) { $stylesheet = $_GET['stylesheet']; $stylesheet = strip_tags($stylesheet); if (!setcookie("stylesheet", $stylesheet, time()+(7 * 24 * 60 * 60)) ) die ("could not set cookie!"); header("Location: $ref"); } else { header("Location: $ref"); } ?>[/PHP] and then I have this at the top of my pages: [PHP]<?php if (!isset($_COOKIE["stylesheet"])) { echo "there is no cookie"; $stylesheet = 'white'; } else if ((isset($_COOKIE["stylesheet"])) && ( (strlen($_COOKIE["stylesheet"]) < 25) && (strlen($_COOKIE["stylesheet"]) > 1) ) ) { echo "there is a cookie!"; $stylesheet = strip_tags($_COOKIE["stylesheet"]); echo $stylesheet; } else { echo "the cookie is too big!"; $stylesheet = 'white'; } $form = ' <a href="/stylesheets.php?stylesheet=white">White</a> - ' .'<a href="/stylesheets.php?stylesheet=blue">Blue</a> ' .'<a href="/stylesheets.php?stylesheet=green">Green</a> '; ?>[/PHP] And then this in my header: [PHP]<link rel="stylesheet" type="text/css" href="/themes/code2design/<?php echo $stylesheet; ?>.css" media="screen,projection" />[/PHP] Now for some reason I get random style sheets, like i could click on "stylesheet=white" and after the cookie is set and I am sent back to the page (see stylesheets.php) my code shows that "blue" is the value for "stylesheets"??? And just other weird things... Here are some similar scripts: http://www.dyn-web.com/dhtml/sizefont/sizerdx.php http://raena.net/2003/12/06/return-of-the-...-size-together/ http://alistapart.com/articles/phpswitch/ http://www.joe2torials.com/view_tutorial.php?view=52 http://www.456bereastreet.com/archive/2006...sheet_switcher/ http://www.gr0w.com/articles/code/css_styl...g_php/index.php |
|
|
|
|
|
#2 |
|
Programmer
Join Date: Jul 2005
Posts: 62
Rep Power: 4
![]() |
Could you supply a link? Or is this on a personal server?
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: Aug 2006
Posts: 11
Rep Power: 0
![]() |
Sorry, I can't supply a link... but it is running on a 1and1.com server.
::::::::::::::::::::::::::::::::: Ok, weird. For the first time ever, IE is actually working with this code while the problem seems to be with FireFox?!? In IE the style changes just fine... but in firefox it chooses its own style. |
|
|
|
|
|
#4 | |
|
Programmer
Join Date: Jul 2005
Posts: 62
Rep Power: 4
![]() |
Quote:
Tools > Options > Privacy > Show Cookies Then search for your site. See what the cookie says. Or in the URL bar you could just type: javascript:alert(document.cookie);void(0); |
|
|
|
|
|
|
#5 |
|
Newbie
Join Date: Aug 2006
Posts: 11
Rep Power: 0
![]() |
FireFox creates two cookies
Ok...
Seems FireFox creates two cookies named stylesheet=blue stylesheet=green How can FF get away with two different cookies named the same? Also, I looked at the cookies with the Web Developer 1.0.2 addon for firefox 2 and it only shows one cookie; blue. |
|
|
|
|
|
#6 |
|
Programmer
Join Date: Jul 2005
Posts: 62
Rep Power: 4
![]() |
Does one have www. before and the other not?
|
|
|
|
|
|
#7 |
|
Programmer
Join Date: Apr 2006
Posts: 35
Rep Power: 0
![]() |
so.... it would seem the page doesnt know which cookie to handle.
$cookie = $_COOKIE['stylesheet'];
if(!empty($cookie)) {
setcookie("stylesheet", "", time()-3600); //set cookie to expire a hour before(basically remove cookie)
}
setcookie("stylesheet","COOKIE INFO HERE",time()+3600);Think that should work (although i havent tested). I know that removing cookie then recreating shouldnt do much but if FF is duplicating at least this stop it.
__________________
this forum rules you guys are great! thanks to all who help piercy |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| What Style Do You Program With? | Darkhack | Other Programming Languages | 1 | Feb 10th, 2006 2:07 AM |
| PFO Style Site Navigation Links | B3TA_SCR1PT3R | Community Announcements and Feedback | 3 | Jan 17th, 2006 10:37 PM |
| Eclipse Style Tabs | swmk | Java | 0 | Nov 28th, 2005 10:46 AM |
| Free Style Component | BlueNight | C++ | 0 | Nov 6th, 2005 3:20 PM |
| changing font style | blueandconfused | HTML / XHTML / CSS | 4 | May 2nd, 2005 3:46 PM |