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