php實(shí)現(xiàn)通過(guò)cookie換膚的方法
本文實(shí)例講述了php實(shí)現(xiàn)通過(guò)cookie換膚的方法。分享給大家供大家參考。具體如下:
saveStyleSheet.php頁(yè)面如下:
<?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頁(yè)面如下:
<!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>
希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。
相關(guān)文章
一個(gè)PHP緩存類代碼(附詳細(xì)說(shuō)明)
一個(gè)PHP緩存類代碼,后面都有詳細(xì)的說(shuō)明,學(xué)習(xí)php的朋友可以參考下。2011-06-06PHP實(shí)現(xiàn)的簡(jiǎn)單分頁(yè)類及用法示例
這篇文章主要介紹了PHP實(shí)現(xiàn)的簡(jiǎn)單分頁(yè)類及用法,結(jié)合實(shí)例形式分析的PHP分頁(yè)類的功能、定義與具體使用技巧,需要的朋友可以參考下2016-05-05PHP strtotime函數(shù)用法、實(shí)現(xiàn)原理和源碼分析
這篇文章主要介紹了PHP strtotime函數(shù)用法、實(shí)現(xiàn)原理和源碼分析,本文講解了strtotime函數(shù)的一些用法、strtotime函數(shù)的實(shí)現(xiàn)基本原理、strtotime(“-1 month”)求值失敗的原因等內(nèi)容,需要的朋友可以參考下2015-02-02PHP簡(jiǎn)單檢測(cè)網(wǎng)址是否能夠正常打開的方法
這篇文章主要介紹了PHP簡(jiǎn)單檢測(cè)網(wǎng)址是否能夠正常打開的方法,涉及php中curl的簡(jiǎn)單使用技巧,需要的朋友可以參考下2016-09-09使用游標(biāo)進(jìn)行PHP SQLSRV查詢的方法與注意事項(xiàng)
在 PHP 中使用 SQLSRV 查詢時(shí),如果查詢結(jié)果集較大,可以考慮使用游標(biāo)來(lái)提高查詢效率。使用游標(biāo)可以將查詢結(jié)果集分成多個(gè)小部分進(jìn)行處理,減輕服務(wù)器的負(fù)擔(dān),提高查詢性能2023-05-05jquery+php+ajax顯示上傳進(jìn)度的多圖片上傳并生成縮略圖代碼
這篇文章主要介紹了jquery+php+ajax顯示上傳進(jìn)度的多圖片上傳并生成縮略圖代碼,可實(shí)現(xiàn)帶有進(jìn)度條效果的多圖上傳功能與生成縮略圖功能,是web開發(fā)中非常實(shí)用的技巧,需要的朋友可以參考下2014-10-10php實(shí)現(xiàn)數(shù)組中索引關(guān)聯(lián)數(shù)據(jù)轉(zhuǎn)換成json對(duì)象的方法
這篇文章主要介紹了php實(shí)現(xiàn)數(shù)組中索引關(guān)聯(lián)數(shù)據(jù)轉(zhuǎn)換成json對(duì)象的方法,基于Yii框架分析了php數(shù)組與json格式數(shù)據(jù)的轉(zhuǎn)換技巧,需要的朋友可以參考下2015-07-07PHPMailer發(fā)送郵件功能實(shí)現(xiàn)流程
隨著企業(yè)化的管理越來(lái)越規(guī)范,各種項(xiàng)目管理系統(tǒng)中,都需要加入到郵件實(shí)時(shí)通知功能,所以在項(xiàng)目中如何整合發(fā)郵件功能,其實(shí)也是很重要的一點(diǎn)。本文為大家介紹了PHP實(shí)現(xiàn)郵件實(shí)時(shí)通知功能的示例代碼,需要的可以參考一下2022-12-12