• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php通过cookie切换网页风格皮肤

php 搞代码 3年前 (2022-01-22) 21次浏览 已收录 0个评论

php如何通过cookie切换网页风格?这篇文章主要介绍了php实现通过cookie换肤的方法,通过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="saveSty<a style="color:transparent">来@源gao*daima.com搞@代#码网</a><strong>搞gaodaima代码</strong>leSheet.php">Default Style Sheet</a></body></html>

相关推荐:

PHP高级教程:PHP Cookies

php Cookies操作类(附源码)

PHP Cookies 常用于识别用户

以上就是php通过cookie切换网页风格皮肤的详细内容,更多请关注搞代码gaodaima其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php通过cookie切换网页风格皮肤

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址