3rd party Counter script trouble

I am a new DH customer, and have ported a number of pages from a previous service. Many of these pages have hit counters, all using a small php script I picked up a few years ago. I edited the individual pages’ scripts as best I could for the new environment, and created local .dat files.

Of the first set of pages I’m debugging, only the initial “home” page counter works as expected (advances for each new session, doesn’t for refreshes.) All the other pages linked from it properly display the contents of the separate .dat files, but the php scripts apparently do not update the files.

I’d really appreciate any input that can help me debug and repair this!

Home page (works):
One page that doesn’t work:
(Counters are at the bottom of each page)

All pages use similar in-line code, except for the script name:

All scripts are the same, except for the dat file name:

<?php $filename = 'PWS_Home_counter.dat'; session_save_path("../phpsessions"); session_start(); if (!isset($_SESSION['visitor_counter']) AND is_writable($filename)) { $count = file_get_contents($filename); if (is_numeric($count)) { $count++; $handle = fopen($filename,"w"); fwrite($handle,"$count"); fclose($handle); $_SESSION['visitor_counter'] = $count; } } else { //$count = $_SESSION['visitor_counter']; $count = file_get_contents($filename); } $width = (strlen($count)*8)+8; $im = @imagecreate($width, 18); $background_color = imagecolorallocate($im,255,255,255); $text_color = imagecolorallocate($im,0,0,0); imagestring($im,4,4,2,$count,$text_color); imagepng($im); imagedestroy($im); ?>

Try placing the session_start to the beginning of your script.

My website

PHP session has to start before html header.

do something like this

<?php session_start(); ?> <?php // the rest of the codes ?>

Save [color=#CC0000]$97[/color] (max discount) on dreamhost by using promo code: [color=#CC0000]97CRAZY[/color].

Actually, you shouldn’t have any problem with the session stuff. My guess is that you need to change permissions to make the file writable.

Simon Jessey | Keystone Websites
Save $97 on yearly plans with promo code [color=#CC0000]SCJESSEY97[/color]

Thanks to all of you who replied!
Late yesterday, I found at least one way to fix it, after a hint from Joshua at DH that it looked like all the pages were using the same session. I left the session path the same, but edited the scripts to make each session variable unique.
Now the scripts look like:
if (!isset($_SESSION[‘Home_visitor_counter’]) AND is_writable($filename)) {

if (!isset($_SESSION[‘Images_visitor_counter’]) AND is_writable($filename)) {

They worked fine under another host, but I wasn’t surprised to find at least some problems. This has been it, so far!