<?php /*
   +------------------------------------------------------------------+
   | MikeCherim.com                                                   |
   | PHP: Font Sizer                                                  |
   | PHP Hypertext Preprocessor                                       |
   | Copyright July 2006                                              |
   | Use with attribution by visible link please!                     |
   | Attribute to: <a href="http://green-beast.com/">Mike Cherim</a>  |
   +------------------------------------------------------------------+
*/
?>

<?php // THIS IS PHP PART 1 OF 2 *************************************
/*
  INSTRUCTIONS:
  Place this part one at the very top of the page as the cookie must be
  served first. This goes above even the document type declaration (DTD)
*/
##################################################
// Configure your font sizes

   
$normal_font_size=    "100%"; // This sets the default/normal size
   
$large_font_size=     "120%";
   
$larger_font_size=    "140%";
   
$largest_font_size=   "160%";

    
// Begin scripting - No need to edit below this point
##################################################
/*
  split variable to use it in two ways. If the cookie isn't
  accepted, this is the default size (as defined above)
*/
   
$php_font_size = "".$normal_font_size."";

// grab user's cookie and return his/her pref
if(isset( $_COOKIE["pfs"] ) && !isset( $_GET["pfs"]) ) {
   
$php_font_size = $_COOKIE["pfs"];
}

/*
  setting the pref, give the cookie and its life-span.
  font size value returned
*/
if(isset( $_GET["pfs"]) ) {
   
setcookie( "pfs", "".$_GET["pfs"]."", time()+60*60*24*30 );
   
$php_font_size = "".$_GET["pfs"]."";
}

// I now create an array of the configured variables
   
$pfs_sizes = array( ''.$normal_font_size.'',
                       
''.$large_font_size.'',
                       
''.$larger_font_size.'',
                       
''.$largest_font_size.'' );

/*
  then I match the variable to be echoed to the variables in the array
  and if it's not a match I reset the echoed variable with the normal size
  font variable
*/
if(!in_array($php_font_size, $pfs_sizes) ) {
    
$php_font_size = $normal_font_size;
}

/*
  this isn't really needed, but it is one string so why not. if another variable
  got by for whatever reason, this would convert its single and double quotes
  and < and > to the proper html character entities
*/
    
$php_font_size = htmlspecialchars("$php_font_size", ENT_QUOTES);
?>





<?php
// THIS IS PHP PART 2 OF 2 *************************************
/*
  INSTRUCTIONS:
  Place this part two in the <head> but be sure to place it AFTER
  your CSS import or link as this must be downstream in the cascade
  to allow the pref to override the default styles

  In this experiment I am styling just a paragraph, but normally,
  this would be "body" instead of "#exp_content p.pfs"
*/
?>

<style type="text/css" media="screen">
#exp_content p.pfs {
/* this is the dynamic output */
  font-size : <?php echo(''.$php_font_size.''); ?>;
}
</style>