3rd party Counter script trouble

apps

#1

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):
http://advanceassociates.com/WallDial/PWS_Home.html
One page that doesn’t work:
http://advanceassociates.com/WallDial/TechnicalInfoPage.html
(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); ?>

#2

Try placing the session_start to the beginning of your script.
Silk

My website


#3

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].


#4

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]


#5

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:
session_save_path("…/phpsessions");
session_start();
if (!isset($_SESSION[‘Home_visitor_counter’]) AND is_writable($filename)) {

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

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

Dave