国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

php實(shí)現(xiàn)通過cookie換膚的方法

2024-05-04 23:37:44
字體:
供稿:網(wǎng)友

這篇文章主要介紹了php實(shí)現(xiàn)通過cookie換膚的方法,通過cookie存儲用戶選擇信息實(shí)現(xiàn)換膚效果,具有一定參考借鑒價值,需要的朋友可以參考下

本文實(shí)例講述了php實(shí)現(xiàn)通過cookie換膚的方法。分享給大家供大家參考。具體如下:

saveStyleSheet.php頁面如下:

 

 
  1. <?php  
  2. function styleSheet($currentCookie){  
  3. // Get Current Style Sheet  
  4. $currentCookie = $_COOKIE["StyleSheet"];  
  5. // Get New cookie file name  
  6. switch($_GET['style']){  
  7. case 1:  
  8. $value = 'style1.css';  
  9. break;  
  10. case 2:  
  11. $value = 'style2.css';  
  12. break;  
  13. case 3:  
  14. $value = 'style3.css';  
  15. break;  
  16. default:  
  17. $value = 'style.css';  
  18. break;  
  19. }  
  20. // If the user views this page, without using  
  21. // style=... then set cookie to the default  
  22. if(!isset($_GET['style'])){  
  23. $value = 'style.css';  
  24. }  
  25. // If the new value doesn't equal the old value allow cookie change  
  26. if(isset($value)||$currentCookie!=$value||isset($currentCookie)){  
  27. setcookie("StyleSheet", $value, time()+600000); /* expires in 10,000 hours*/ 
  28. return $_COOKIE["StyleSheet"];  
  29. }else{  
  30. return $_COOKIE["StyleSheet"];  
  31. }  
  32. if(isset($_GET['style'])){  
  33. header("Location: ".$_SERVER['HTTP_REFERER']);  
  34. exit;  
  35. }  
  36. }  
  37. ?> 

index.php頁面如下:

 

 
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
  3. <html xmlns="http://www.w3.org/1999/xhtml"
  4. <head> 
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
  6. <title>My Test Page</title> 
  7. <?php  
  8. include("saveStyleSheet.php");  
  9. if(isset($_COOKIE["StyleSheet"])){  
  10. ?>  
  11. <link rel="stylesheet" type="text/css" href="stylesheets/ <?php echo styleSheet($_COOKIE["StyleSheet"]); ?> " /> 
  12. <?php  
  13. }else{  
  14. ?>  
  15. <link rel="stylesheet" type="text/css" href="stylesheets/style.css" /> 
  16. <?php  
  17. }  
  18. ?>  
  19. </head> 
  20. <body> 
  21. <a href="saveStyleSheet.php?style=1">Style Sheet 1</a><br /> 
  22. <a href="saveStyleSheet.php?style=2">Style Sheet 2</a><br /> 
  23. <a href="saveStyleSheet.php?style=3">Style Sheet 3</a><br /> 
  24. <a href="saveStyleSheet.php">Default Style Sheet</a> 
  25. </body> 
  26. </html> 

希望本文所述對大家的php程序設(shè)計有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 六枝特区| 中阳县| 玛纳斯县| 新竹县| 白山市| 南昌市| 工布江达县| 开封县| 长岭县| 仪征市| 沙田区| 丽水市| 广德县| 察雅县| 新晃| 育儿| 连南| 嘉善县| 永年县| 常熟市| 萍乡市| 安国市| 句容市| 天长市| 饶平县| 新巴尔虎右旗| 会理县| 安福县| 佳木斯市| 云阳县| 金昌市| 霍州市| 通榆县| 阿拉尔市| 通化市| 赤峰市| 霍邱县| 色达县| 靖江市| 深泽县| 弋阳县|