session colours

Ask about a PHP problem here.
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

session colours

Post 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
I would put a signature.. BUT, i don't have the time.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: session colours

Post 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.
Image
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

Re: session colours

Post 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]

?
I would put a signature.. BUT, i don't have the time.
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

Re: session colours

Post 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?
I would put a signature.. BUT, i don't have the time.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: session colours

Post 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 ?
Image
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

Re: session colours

Post 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..
I would put a signature.. BUT, i don't have the time.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: session colours

Post 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]
Image
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: session colours

Post 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.
Image
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

Re: session colours

Post 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?
I would put a signature.. BUT, i don't have the time.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: session colours

Post by jacek »

[syntax=php]$_SESSION['css'] = $_POST['css'];[/syntax]

??
Image
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

Re: session colours

Post 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 :\
I would put a signature.. BUT, i don't have the time.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: session colours

Post 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.
Image
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

Re: session colours

Post 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..
I would put a signature.. BUT, i don't have the time.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: session colours

Post 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.
Image
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

Re: session colours

Post 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..
I would put a signature.. BUT, i don't have the time.
User avatar
EcazS
Posts: 789
Joined: Fri May 06, 2011 5:29 pm

Re: session colours

Post 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
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

Re: session colours

Post 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?
I would put a signature.. BUT, i don't have the time.
User avatar
EcazS
Posts: 789
Joined: Fri May 06, 2011 5:29 pm

Re: session colours

Post 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]
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

Re: session colours

Post 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 :)
I would put a signature.. BUT, i don't have the time.
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

Re: session colours

Post by ashwood »

ive sorted it.. i forgot session_start() on the style.php page..
I would put a signature.. BUT, i don't have the time.
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

Re: session colours

Post 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?
I would put a signature.. BUT, i don't have the time.
Post Reply