PHP switch web-style skins via cookies

Source: Internet
Author: User
How does PHP switch Web style via cookies? This article mainly introduced the PHP implementation through the cookie skin method, through the cookie storage user choice information realizes the skin change effect, hoped to be helpful to everybody.

Specific as follows:

The savestylesheet.php page is as follows:


<?php function StyleSheet ($currentCookie) {//Get current Style Sheet $current   Cookie = $_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 cookies to the default If (!isset ($_get[' style ')   ) {$value = ' style.css '; }//If the new value doesn ' t equal the old value to allow cookie change If (isset ($value) | | $currentCookie! = $value | | Isset ($currentCookie)) {Setcookie ("StyleSheet", $value, Time () +600000);/* expires in hours*/return $_cook   ie["StyleSheet"];   }else{return $_cookie["StyleSheet"];     } if (Isset ($_get[' style ')) {header ("Location:". $_server[' Http_referer '));   Exit }}; 


The index.php page is as follows:


<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

Related recommendations:

PHP Advanced Tutorial: PHP Cookies

PHP Cookies Operation class (with source code)

PHP Cookies are often used to identify users

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.