I am having a problem with two things on my site, both of which work perfectly independently, but occasionally fail when combined. I am using a CMS (or more specifically, a news posting script) that is part homemade and part scrapped together from tuts. It's php 4.3 + mysql.

The first is basic php page caching saving cached pages as "cache/$id.html". To expire the cached files, I'm using filetime comparison against a dynamically created file such as "cache/t$id.txt".

The style switcher script is from A List Apart. It otherwise works, but as an example: if I am on the index page and using style A then click to page "...&id=3", switch to style B, click back to the index page, the style also switchs back to style A.

The code...

setcookie ('sitestyle', $css, time()+31536000,	'/', mysite.com', '0');

if (isset($_GET['id']) && file_exists("cache/t.".$_GET['id'].".txt")) {
else {
header("Location: $HTTP_REFERER");
... If user switchs the style, touch the touch file. The "$_GET['id']" is set via my link to switch styles: "style.php?css=lofi&id=[this-page-id]".

caching (has become messy):
include 'config.php';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

/* -------- begin cache */ 

$cacheDir  = dirname(__FILE__) . '/cache/';
if (isset($_GET['id'])) { $cacheFile = $cacheDir . $_GET['id'] . '.html'; } 
else { $cacheFile = $cacheDir . 'index.html'; }   

if (isset($_GET['id']) && !file_exists("cache/t".$_GET['id'].".txt")) {
touch("cache/t".$_GET['id'].".txt"); chmod("cache/t".$_GET['id'].".txt",0666); }
elseif (!file_exists("cache/tindex.txt")) { 
touch("cache/tindex.txt"); chmod("cache/tindex.txt",0666); }

if (file_exists($cacheFile) && (filemtime("cache/t".$_GET['id'].".txt")) < filemtime($cacheFile)) { 
		echo "<!-- File cached: ".date('H:i', filemtime($cacheFile))." -->\n"; 

...html stuff
...end caching code
That is the coding. Can you see something I'm missing or even need to remove?