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

[syntax=php]<link rel="stylesheet" type="text/css" href="ext/css/<?php echo $_SESSION['css']; ?>" />[/syntax]
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

[syntax=php]<link rel="stylesheet" type="text/css" href="ext/css/<?php echo $_SESSION['css']; ?>" />[/syntax]
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?
[syntax=php]$_SESSION['css']==$red_css[/syntax]

?

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.

[syntax=javascript]dropdown.onchange = function() {
document.getElementById('form').submit();
}[/syntax]

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.

[syntax=php]$_SESION['css'] = 'red.css';[/syntax]
which will work as long as you have

[syntax=php]session_start();[/syntax]
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
[syntax=php]$_SESSION['css'] = $_POST['css'];[/syntax]

??

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

[syntax=xhtml]<a href="?css=red">Red</a>[/syntax]
And then set the session to the value.

[syntax=php]if (isset($_GET['css'])){
$_SESSION['css'] = $_POST['css'];
}[/syntax]
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

[syntax=xhtml]<a href="?css=red">Red</a>[/syntax]
And then set the session to the value.

[syntax=php]if (isset($_GET['css'])){
$_SESSION['css'] = $_POST['css'];
}[/syntax]
It would also be worth making sure the css file exists before allowing it to be changed.


this:

[syntax=php]if (isset($_GET['css'])){
$_SESSION['css'] = $_POST['css'];
}[/syntax]

if i change to

[syntax=php]if (isset($_GET['css'])){
$_SESSION['css'] = "style_red/stylesheet.css";
}[/syntax]

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

[syntax=php]
if($_SESSION['css']="")
{
$_SESSION['css']="default/stylesheet.css"
}
[/syntax]

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
[syntax=php]
if(empty($_SESSION['css']))
[/syntax]

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:
[syntax=php]if(empty($_SESSION['stylesheet']))
{
echo "Empty";
}
else
echo "Not Empty";[/syntax]

i go http://www.aatm-online.co.uk/style.php which contains..
[syntax=php]$_SESSION['stylesheet']="ashwood";

echo "Changing stylesheet";[/syntax]

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?