Solved

skins using cookies

Posted on 2003-10-22
2
255 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

751 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