Solved

skins using cookies

Posted on 2003-10-22
2
254 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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 …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

740 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