Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 19th, 2006, 1:37 PM   #1
Xeoncross
Newbie
 
Xeoncross's Avatar
 
Join Date: Aug 2006
Posts: 11
Rep Power: 0 Xeoncross is on a distinguished road
Question Changing Style Sheets with PHP

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
Xeoncross is offline   Reply With Quote
Old Nov 19th, 2006, 1:51 PM   #2
Eryk
Programmer
 
Join Date: Jul 2005
Posts: 62
Rep Power: 4 Eryk is on a distinguished road
Could you supply a link? Or is this on a personal server?
Eryk is offline   Reply With Quote
Old Nov 19th, 2006, 1:52 PM   #3
Xeoncross
Newbie
 
Xeoncross's Avatar
 
Join Date: Aug 2006
Posts: 11
Rep Power: 0 Xeoncross is on a distinguished road
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.
Xeoncross is offline   Reply With Quote
Old Nov 19th, 2006, 1:57 PM   #4
Eryk
Programmer
 
Join Date: Jul 2005
Posts: 62
Rep Power: 4 Eryk is on a distinguished road
Quote:
Originally Posted by Xeoncross View Post
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.
Well that would mean that its not a server-side error, but rather the way its handled by the client. Perhaps something wrong with setting the cookies. After the cookie supposed to have been sent go to
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);
Eryk is offline   Reply With Quote
Old Nov 19th, 2006, 2:24 PM   #5
Xeoncross
Newbie
 
Xeoncross's Avatar
 
Join Date: Aug 2006
Posts: 11
Rep Power: 0 Xeoncross is on a distinguished road
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.
Xeoncross is offline   Reply With Quote
Old Nov 19th, 2006, 3:47 PM   #6
Eryk
Programmer
 
Join Date: Jul 2005
Posts: 62
Rep Power: 4 Eryk is on a distinguished road
Does one have www. before and the other not?
Eryk is offline   Reply With Quote
Old Nov 22nd, 2006, 1:24 PM   #7
piercy
Programmer
 
Join Date: Apr 2006
Posts: 35
Rep Power: 0 piercy is on a distinguished road
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
piercy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:09 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC