本篇文章主要介绍php基于cookie实现换肤的方法,感兴趣的朋友参考下,希望对大家有所帮助。
本文实例讲述了php实现通过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><html><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 实现的将图片转换为ascii码
通过php实现统计在线人数的方法
php程序中获取汉字拼音的首字母的方法
以上就是php基于cookie实现换肤的方法的详细内容。