Save font-size to cookie
This code will let user change the font-size. And will save the changed font-size to cookie:
<?php
if (!empty($_COOKIE['fontsize'])) {
$fontsize = $_COOKIE['fontsize'];
} elseif (!empty($_COOKIE['fontsizeR'])) {
$fontsize = $_COOKIE['fontsizeR'];
} else {
$fontsize = 12;
}
if (isset($_GET['font'])) {
if ($_GET['font'] == ‘base’) {
$fontsize = 12;
} else if (($_GET['font'] == ‘dec’) && ($fontsize > 11)) {
$fontsize -= 1;
} else if (($_GET['font'] == ‘inc’) && ($fontsize < 15)) {
$fontsize += 1;
}
setcookie('fontsize', $fontsize, NULL, '/');
setcookie('fontsizeR', $fontsize, time()+60*60*24*365, '/');
}
function get_fontsize_link($action) {
$uri = current(preg_split('/[&|?]{1}font=/', $_SERVER['REQUEST_URI']));
$ref = str_replace('&', '&', $uri);
if (strpos($ref, '?') === FALSE) {
$ref .= '?font=' . $action;
} else {
$ref .= '&font=' . $action;
}
return $ref;
}
?>
......
<style type="text/css">
<!--
#content {
font-size: <?php echo $fontsize; ?>px;
}
-->
</style>
......
<div id="size">
<a id="size1" href="<?php echo get_fontsize_link('inc'); ?>">[A]</a>
<a id="size2" href="<?php echo get_fontsize_link('base'); ?>">[A]</a>
<a id="size3" href="<?php echo get_fontsize_link('dec'); ?>">[A]</a>
</div>