PHP session variable help.

Qua Sar

Senior member
Jun 27, 2005
365
0
0
hello
i'm trying to create a session variasble that will change the CSS file from style.css to larger.css but it doesn't seem to change... always stays at style.css and i was wondering if anyone could help me.

<?php
session_start();
if(isset($_SESSION['style']))
$_SESSION['style'] = $_SESSION['style'];
else
$_SESSION['style'] = "style.css";
?>

This is the code that starts the session then determines if the variable is empty if not it will stay the same otherwise it will make it style.css

then when you click a link that says click here to get bigger it will pass larger.css into the style sesion variable and go back to the main site. here's teh code for the link.

<a href="http://www.revmortpanj.com/rmpj/site.php?style='larger.css'">Click here for bigger text</a>

does anybody have any ideas? I found this ide aon the forum and tried it and have been looking on how to change session variables but haven't found anything useful ... idk why i'm going to keep looking but though i'd post this, up here. Any help would be great
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
By using site.php?style=larger.css you are using a query string, whose variables are accessible via $_GET['style']. You would check isset on it first, then if it passes set $_SESSION['style'] = $_GET['style'], otherwise do as you currently do with the else.
 

NiKeFiDO

Diamond Member
May 21, 2004
3,901
1
76
yeah, in fact, you don't need to use SESSION at all, you should be using GET"
<?php
if(isset($_GET['style']) && $_GET['style'] != '') {
echo '<style type="text/css" src="$_GET['style']"></style>';
} else {
echo '<style type="text/css" src="default.css"></style>';
}
?>
 

Alex

Diamond Member
Oct 26, 1999
6,995
0
0
Originally posted by: NiKeFiDO
yeah, in fact, you don't need to use SESSION at all, you should be using GET"
<?php
if(isset($_GET['style']) && $_GET['style'] != '') {
echo '<style type="text/css" src="$_GET['style']"></style>';
} else {
echo '<style type="text/css" src="default.css"></style>';
}
?>

thats what i'd do (or something very similar anyway)... a word of caution though:

since $_GET variables can easily be changed by the sites visitors I'd implement some sort of validation to avoid potential errors. For example:

<?php
// create an array with all possible styles
$possibleStyles[] = 'small';
$possibleStyles[] = 'large';

if(isset($_GET[style] and $_GET[style]!=''){
// check to see if the value of $_GET[style] matches one of the possible styles
if(array_search($possibleStyles, $_GET[style])!==false)
echo '<style type="text/css" src="$_GET[style]"></style>';
else
echo '<style type="text/css" src="default.css"></style>';
}

haven't tested the code but it should work. this way you can avoid someone loading the page with a bogus css file that doesn't exist or even worse, with one of their own (unless you specifically want the user to be able specify external stylesheets.
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
I think you guys are missing the point of him using the session variable. If you goto his link, he wants the larger text to be site wide once you choose a large/small version. If you do it the way you two posted, you'd have to pass the $_GET variable to every single page the user visits.....
 

presidentender

Golden Member
Jan 23, 2008
1,166
0
76
Originally posted by: Crusty
I think you guys are missing the point of him using the session variable. If you goto his link, he wants the larger text to be site wide once you choose a large/small version. If you do it the way you two posted, you'd have to pass the $_GET variable to every single page the user visits.....

So?
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
Originally posted by: presidentender
Originally posted by: Crusty
I think you guys are missing the point of him using the session variable. If you goto his link, he wants the larger text to be site wide once you choose a large/small version. If you do it the way you two posted, you'd have to pass the $_GET variable to every single page the user visits.....

So?

It's a waste of resources.
 

NiKeFiDO

Diamond Member
May 21, 2004
3,901
1
76
Yes, in that case, a session variable will do nicely.
You don't want GET variables cluttering up your URL if you can avoid it.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |