Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

skins using cookies

Posted on 2003-10-22
2
Medium Priority
?
259 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 500 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.
Suggested Courses

886 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