Solved

skins using cookies

Posted on 2003-10-22
2
252 Views
Last Modified: 2006-11-17
Hi.  I'm using cookies so that the users on my site may select a 'skin't that they prefer to view.  It works great as it is...but uses querystrings which I'd like to avoid.  Ideally, I would like coloured boxes on every page and each colour represents a new skin.  Once selected it is stored in the cookie.

This is the cookiecheck page which is included on every page....
<?

$total_skins = 14;
$default_skin = 1;

  if (isset($_REQUEST['newskin'])) {
    $newskin=(int)$_REQUEST['newskin'];
    if ( ($newskin<1) OR ($newskin>$total_skins) ) $newskin=$default_skin;
  } elseif (isset($_REQUEST['skin'])) {
    $newskin=(int)$skin;
    if ( ($skin<1) OR ($skin>$total_skins) ) $newskin=$default_skin;
  } else $newskin=$default_skin;

  $skin=$newskin;
  setcookie ('skin', "", time() - 3600);
  setcookie('skin',$newskin,time()+(86400*365),'/');
  setcookie('skin',$newskin,time()+(86400*365),'/','.domesticat.net');
  $skin=$newskin;


    $headervar = "includes/header";
    $footervar = "includes/footer";
    $extension = ".php";
?>

So far...the html is like this with the headers and footers being part of the new skin.

<? include($headervar.$skin.$extension); ?><br>

<a href="index.php?newskin=1">Skin 1</a><br>
<a href="index.php?newskin=2">Skin 2</a><br>

<? include($footervar.$skin.$extension); ?>

How could I adapt this so that we don't use querystrings?

Thanks
:-)
0
Comment
Question by:aspguru28
2 Comments
 
LVL 11

Accepted Solution

by:
shmert earned 125 total points
ID: 9601884
Use javascript to set the skin cookie, with query strings as a fallback mechanism

<script language="javascript">
function useSkin(skin) {
    var nextYear = new Date();
    nextYear.setFullYear(nextYear.getFullYear() + 1);
    document.cookie = 'skin=' + skin + '; expires=' + nextYear;
    return false;
}
</script>

<a href="index.php?newskin=1" onclick="return useSkin(1);">Skin 1</a>

This method will work for both javascript and non-javascript browsers.  If a browser has javascript, the useSkin() function will return false, preventing the anchor tag from loading the new page.
0
 

Author Comment

by:aspguru28
ID: 10055614
Thank you shmert.......sorry to take so long with a response.  I have been trying different methods.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question