note 63191 deleted from function.session-cache-limiter by betz

From: Date: Thu, 16 Mar 2006 10:49:33 +0000
Subject: note 63191 deleted from function.session-cache-limiter by betz
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-105916@lists.php.net to get a copy of this message
Note Submitter: RedScourge aT No Spam GMAIL dot comm ---- i made a simple file-based content management system that involved making a method call to a master file that outputs some page style wrapper html and another method to close all the html tags, and what i would do is include this file in all pages on the site, call the opening method, type all my content for that page, then call the closing method. i use output buffering, sessions, and a form that allows the user to change the stylesheet the site uses via a cookie. in the master file, i had a method that reads the value of the cookie and chooses the filename for the stylesheets and puts that into the <link rel> tags for the stylesheets, and i used a seperate file that i would include which contained the method that actually sets a cookie if the user posts to the stylesheet change form. even though i had output buffering on, i had to change it so the entire cookie setting and getting method that alters the path for the stylesheet to the master file, because output buffering didnt seem to work when it involves method calls to other included files. heres an example of what the stylesheet cookie code looks like now: function setSkin(){ //if were changing the skin if(isset($_POST['skin'])){ //grab number and set the cookie $num=$_POST['skin']; setcookie("skin", $num, time()+9999999, "/"); //update the stylesheet filepaths $this->skinmainfile="css/divstyle".$num.".css"; $this->skinformfile="css/formstyle".$num.".css"; } //if we havent changed the skin, grab the number and update stylesheet paths elseif(isset($_COOKIE)){ $num=$_COOKIE['skin']; $this->skinmainfile="css/divstyle".$num.".css"; $this->skinformfile="css/formstyle".$num.".css"; } } basically the structure of how it works was like this: index.php: <?php require_once("priv/content_builder.inc.php"); $contentBuilder = new contentBuilder(); $contentBuilder->HTMLBegin("menu1.php", "website :: Home", "index.php", "/", 0); page content goes here $contentBuilder->HTMLEnd(""); exit; ?> the contentBuilder class has methods for adding headers to the <head> tag such as stylesheet, and the stylesheet was being selected according to the cookie value, in this way. basically, i had to instead call my cookie method and set the value to be used for the stylesheet url before i did any output. the moral of this story: output buffering might not always work for you in all contexts, when multiple file includes are involved, when the included files may send headers. so i guess its best to code so you dont even NEED to rely on output buffering, but instead to just use it for special applications, or not have to worry about header sending order in a single file. using output buffering on one file and including a series of other files which may send headers is risky i guess. oh and, somebody, correct me if im wrong.

« previous php.notes (#105916) next »