Page 1 of 2
session colours
Posted: Wed Jun 01, 2011 4:53 pm
by ashwood
basically i want to put a list of colours and when the user click the colour the stylesheet for that colour stays loaded.. i think its sessions?
would i do it in a form and form php to set the session, maybe a bit of a start would be helpful.. thanks
Re: session colours
Posted: Wed Jun 01, 2011 4:58 pm
by jacek
You can store the name of the css file in the session or database, then output it in the link tag
<link rel="stylesheet" type="text/css" href="ext/css/<?php echo $_SESSION['css']; ?>" />
Something along those lines may work.
Re: session colours
Posted: Wed Jun 01, 2011 5:00 pm
by ashwood
jacek wrote:You can store the name of the css file in the session or database, then output it in the link tag
<link rel="stylesheet" type="text/css" href="ext/css/<?php echo $_SESSION['css']; ?>" />
Something along those lines may work.
how do i set the session say i had
orange
yellow
red
blue
and they clicked red how would i set the session?
$_SESSION['css']==$red_css
?
Re: session colours
Posted: Wed Jun 01, 2011 5:13 pm
by ashwood
ive workedi out.. it is what i just put, but im going to do a drop down box butwhen they set the session how would i refresh the page automatically for them?
Re: session colours
Posted: Wed Jun 01, 2011 6:07 pm
by jacek
ashwood wrote:but im going to do a drop down box butwhen they set the session how would i refresh the page automatically for them?
Clicking the submit button for the form with the drop down menu in should refresh the page ?
Re: session colours
Posted: Wed Jun 01, 2011 9:16 pm
by ashwood
jacek wrote:ashwood wrote:but im going to do a drop down box butwhen they set the session how would i refresh the page automatically for them?
Clicking the submit button for the form with the drop down menu in should refresh the page ?
yeah but i don't want a submit button i just want it to drop down and they click and it refreshes not drop down choose then click go..
Re: session colours
Posted: Thu Jun 02, 2011 3:12 pm
by jacek
oh right, you would have to use javascript for that then. you could have the form submitted with the onchange event for the drop down.
dropdown.onchange = function() {
document.getElementById('form').submit();
}
Re: session colours
Posted: Thu Jun 02, 2011 6:28 pm
by jacek
ashwood wrote:Orite mate,
About this session thing at the moment im not bothered about drop downs etc the main thing is setting the session because ive thought somewhere the default skin has to be set.. how do we change that session without destroying the first one because destroying the first logs the user out + no skin so site looks a mess..
Thanks
Ash
You can set a session variable like this.
$_SESION['css'] = 'red.css';
which will work as long as you have
session_start();
at the top of the page.
Re: session colours
Posted: Thu Jun 02, 2011 7:11 pm
by ashwood
yes so that sets the default now how do we change the session when a user clicks a colour which is a link for the css which matches that colour?
Re: session colours
Posted: Thu Jun 02, 2011 7:38 pm
by jacek
$_SESSION['css'] = $_POST['css'];
??
Re: session colours
Posted: Fri Jun 03, 2011 12:55 am
by ashwood
i still dont get it though because rite say i had
<a href='red'>red</a>
and so on..
when they click that i want the session to change to red.. im really lost with all this :\
Re: session colours
Posted: Fri Jun 03, 2011 11:16 am
by jacek
You would link to
<a href="?css=red">Red</a>
And then set the session to the value.
if (isset($_GET['css'])){
$_SESSION['css'] = $_POST['css'];
}
It would also be worth making sure the css file exists before allowing it to be changed.
Re: session colours
Posted: Fri Jun 03, 2011 12:16 pm
by ashwood
jacek wrote:You would link to
<a href="?css=red">Red</a>
And then set the session to the value.
if (isset($_GET['css'])){
$_SESSION['css'] = $_POST['css'];
}
It would also be worth making sure the css file exists before allowing it to be changed.
this:
if (isset($_GET['css'])){
$_SESSION['css'] = $_POST['css'];
}
if i change to
if (isset($_GET['css'])){
$_SESSION['css'] = "style_red/stylesheet.css";
}
that would set the session correct? and change the session['css']; to the red.. which will automatically stop the $_SESSION referring to the default one i am going to have to put at the top of my index page.. which then confuses me more because.. everytime the user clicks home the stylesheet is going to set back to default as it will go
$_SESSION['css'] = "default/stylesheet.css";
<link href='<?php echo $_SESSION['css']'; ?> rel='stylesheet' type='text/css' />
if you get that..
Re: session colours
Posted: Fri Jun 03, 2011 1:21 pm
by jacek
ashwood wrote:that would set the session correct?
Looks like it, you could just try it though
ashwood wrote:everytime the user clicks home the stylesheet is going to set back to default as it will go
indeed, you need to only set the default if there is not one set and they have not clicked on a link.
Re: session colours
Posted: Fri Jun 03, 2011 2:14 pm
by ashwood
jacek wrote:
indeed, you need to only set the default if there is not one set and they have not clicked on a link.
how do i do this because if the user is first visiting the site the default skin needs to be there if you get me..
Re: session colours
Posted: Fri Jun 03, 2011 3:23 pm
by EcazS
ashwood wrote:
how do i do this because if the user is first visiting the site the default skin needs to be there if you get me..
You could check if the session is empty and if it is, set the default session
Re: session colours
Posted: Fri Jun 03, 2011 3:33 pm
by ashwood
EcazS wrote:ashwood wrote:
how do i do this because if the user is first visiting the site the default skin needs to be there if you get me..
You could check if the session is empty and if it is, set the default session
so what
if($_SESSION['css']="")
{
$_SESSION['css']="default/stylesheet.css"
}
that?
Re: session colours
Posted: Fri Jun 03, 2011 4:08 pm
by EcazS
Something along those lines, yes.
You could also use the empty function to see if it's empty
if(empty($_SESSION['css']))
Re: session colours
Posted: Sun Jun 05, 2011 4:20 pm
by ashwood
http://www.aatm-online.co.uk at the top you can see that it says empty thats because i have this:
if(empty($_SESSION['stylesheet']))
{
echo "Empty";
}
else
echo "Not Empty";
i go
http://www.aatm-online.co.uk/style.php which contains..
$_SESSION['stylesheet']="ashwood";
echo "Changing stylesheet";
i go on the style page.. then i go back home.. but the session is still empty?
NOTE: sorry for linking my website but examples may help deal with the issue easier
Re: session colours
Posted: Sun Jun 05, 2011 4:25 pm
by ashwood
ive sorted it.. i forgot session_start() on the style.php page..
Re: session colours
Posted: Sun Jun 05, 2011 8:45 pm
by ashwood
i was thinking when the user is logged in thats when they will be able to change the style.. when they log out it session_destroy() doesnt only log out but it now kills that style session should i leave it like that you think as the user can only change the style when they are logged in?