FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Passing a variable to multiple pages...sort of?





Mosquito.Tyler
So, I have this site...and I got bored so I set up four different color schemes that the user can choose. I have PHP scripts that choose which CSS documents to read based on a URL encoded variable('season').

This site is pretty small, so it is just one PHP index file that includes different files based on another URL encoded variable ('page').

My problem is, if I make a link to a different page:
Code:

<a href="&page=omg">Sub Link</a>


It will change the 'page' variable, but it also does away with the 'season' variable.

How do I switch pages while keeping the same color scheme?

Should I just have PHP write in the existing value in every link(see following code), or is there an easier way?

Code:

<a href="&page=omg&season=<?php echo $_GET['season']; ?>">Sub Link</a>


Thanks for your help.
TheGustav
You could always put the variable into a session when the user chooses it...

Code:
$_SESSION["season"] = $season;


and then retrieve it at the top of each page

Code:
$season = $_SESSION["season"];


If that's anything near what you want. I'm not quite in the right state of mind at the moment, and not sure what you're looking for...

But you could always just throw it through the link like you showed above.
Mosquito.Tyler
TheGustav wrote:
You could always put the variable into a session when the user chooses it...

Code:
$_SESSION["season"] = $season;


and then retrieve it at the top of each page

Code:
$season = $_SESSION["season"];


If that's anything near what you want. I'm not quite in the right state of mind at the moment, and not sure what you're looking for...

But you could always just throw it through the link like you showed above.


Hmm, I forgot about sessions (Ima noob)...Thankyou
Fire Boar
Or you could use cookies... it depends on what you want. Is this a permanent colour scheme thing? If so, use cookies. Sessions should be used if you want them to choose a season every time they visit.
Manofgames
Fire Boar wrote:
Or you could use cookies... it depends on what you want. Is this a permanent colour scheme thing? If so, use cookies. Sessions should be used if you want them to choose a season every time they visit.


But not everyone will have their browser setup to allow your site to leave cookies.
I had that problem with a shoutbox mod I was working on.
I'd suggest using sessions, and passing the session id in the url.
I do it this way:
Code:

//This goes just under session_start()
//Set up trailing url, for passing default vars around
$trailurl = session_id().'&';


Then in each link / form action etc:

Code:

echo '<a href="somewierdpage.php?avar=avalue&'.$trailurl.'">A link to a wierd page</a>';


If you get my meaning, hope this helps
Mosquito.Tyler
Thanks for your help!
Related topics
PHP Toturail
Suggestion: Posts per page
secrets of firefox
Choosing Between Free or Paid Web Hosting
Some questions
Google and Domains: help
Center the site with the <DIV> tag.
Limit results/page
Refine Search
PHPBB multiple accounts signup page?
Form help
Same navigation bar on multiple pages
HTML Single link to open multiple pages
Lot of entries to multiple pages
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.