How to use cookies in php _ PHP-php Tutorial

Source: Internet
Author: User
Tags set cookie
This article mainly introduces how php achieves skin replacement by using cookies, and how to use cookies to store user-selected information for skin replacement, which has some reference value, for more information, see the following example. Share it with you for your reference. The details are as follows:

The saveStyleSheet. php page is as follows:

<?php function styleSheet($currentCookie){   // Get Current Style Sheet   $currentCookie = $_COOKIE["StyleSheet"];   // Get New cookie file name   switch($_GET['style']){     case 1:       $value = 'style1.css';     break;     case 2:       $value = 'style2.css';     break;     case 3:       $value = 'style3.css';     break;     default:       $value = 'style.css';     break;   }   // If the user views this page, without using   // style=... then set cookie to the default   if(!isset($_GET['style'])){     $value = 'style.css';   }   // If the new value doesn't equal the old value allow cookie change   if(isset($value)||$currentCookie!=$value||isset($currentCookie)){     setcookie("StyleSheet", $value, time()+600000); /* expires in 10,000 hours*/     return $_COOKIE["StyleSheet"];   }else{     return $_COOKIE["StyleSheet"];   }   if(isset($_GET['style'])){     header("Location: ".$_SERVER['HTTP_REFERER']);     exit;   } } ?>

The index. php page is as follows:

 My Test Page<?php include("saveStyleSheet.php"); if(isset($_COOKIE["StyleSheet"])){ ?> 
  " /><?php }else{ ?> 
 <?php } ?> Style Sheet 1
Style Sheet 2
Style Sheet 3
Default Style Sheet

I hope this article will help you with php programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.