php實現(xiàn)通過cookie換膚的方法
更新時間:2015年07月13日 14:43:49 作者:不吃皮蛋
這篇文章主要介紹了php實現(xiàn)通過cookie換膚的方法,通過cookie存儲用戶選擇信息實現(xiàn)換膚效果,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了php實現(xiàn)通過cookie換膚的方法。分享給大家供大家參考。具體如下:
saveStyleSheet.php頁面如下:
<?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; } } ?>
index.php頁面如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>My Test Page</title> <?php include("saveStyleSheet.php"); if(isset($_COOKIE["StyleSheet"])){ ?> <link rel="stylesheet" type="text/css" href="stylesheets/ <?php echo styleSheet($_COOKIE["StyleSheet"]); ?> " /> <?php }else{ ?> <link rel="stylesheet" type="text/css" href="stylesheets/style.css" /> <?php } ?> </head> <body> <a href="saveStyleSheet.php?style=1">Style Sheet 1</a><br /> <a href="saveStyleSheet.php?style=2">Style Sheet 2</a><br /> <a href="saveStyleSheet.php?style=3">Style Sheet 3</a><br /> <a href="saveStyleSheet.php">Default Style Sheet</a> </body> </html>
希望本文所述對大家的php程序設(shè)計有所幫助。
相關(guān)文章
PHP strtotime函數(shù)用法、實現(xiàn)原理和源碼分析
這篇文章主要介紹了PHP strtotime函數(shù)用法、實現(xiàn)原理和源碼分析,本文講解了strtotime函數(shù)的一些用法、strtotime函數(shù)的實現(xiàn)基本原理、strtotime(“-1 month”)求值失敗的原因等內(nèi)容,需要的朋友可以參考下2015-02-02使用游標(biāo)進(jìn)行PHP SQLSRV查詢的方法與注意事項
在 PHP 中使用 SQLSRV 查詢時,如果查詢結(jié)果集較大,可以考慮使用游標(biāo)來提高查詢效率。使用游標(biāo)可以將查詢結(jié)果集分成多個小部分進(jìn)行處理,減輕服務(wù)器的負(fù)擔(dān),提高查詢性能2023-05-05jquery+php+ajax顯示上傳進(jìn)度的多圖片上傳并生成縮略圖代碼
這篇文章主要介紹了jquery+php+ajax顯示上傳進(jìn)度的多圖片上傳并生成縮略圖代碼,可實現(xiàn)帶有進(jìn)度條效果的多圖上傳功能與生成縮略圖功能,是web開發(fā)中非常實用的技巧,需要的朋友可以參考下2014-10-10php實現(xiàn)數(shù)組中索引關(guān)聯(lián)數(shù)據(jù)轉(zhuǎn)換成json對象的方法
這篇文章主要介紹了php實現(xiàn)數(shù)組中索引關(guān)聯(lián)數(shù)據(jù)轉(zhuǎn)換成json對象的方法,基于Yii框架分析了php數(shù)組與json格式數(shù)據(jù)的轉(zhuǎn)換技巧,需要的朋友可以參考下2015-07-07