PDA

View Full Version : Visitor counter in php does not work



SPOKMIK
04-06-2008, 01:02 PM
Hello.

I have copied a visitor counter from the net. This includes a php-script, a txt-file (for the count number) a 2 php-lines to insert in the page where the counter should be reproduced (1 in top including the php-script on the page, 1 on the actual site for the counter to appear).
It does not function.

When I test the counter with WAMP on the localhost the counter works well,
also when I create a page with only the 2 php-lines (it to say, without all the text, fotos and stuff).
But when I upload the final page with the counter, well.....nothing - the html-text (you are visitor number:) is reproduced but not the actual count.

I use DreamWeaver CS3, if that is important.

Thanks for any help.

KIM

city_coder
04-06-2008, 02:58 PM
Hmmm interesting, could do with looking at the code that you have used from the web to see what we think.

SPOKMIK
04-07-2008, 02:55 PM
Hmmm interesting, could do with looking at the code that you have used from the web to see what we think.
Hello.

Here comes the code:

(PHP-SCRIPT:)

<?php

session_start();
function counter($updateOn='always', $filename='counter.txt') {
if (file_exists($filename)) {
$myFile = fopen($filename, 'r+');
} else {
$myFile = fopen($filename, 'w+');
}
if (!$myFile) { return -1; }
$fcontent = fread($myFile, filesize($filename)+1);
if ($fcontent == '') $fcontent = 0;
$fsession = isset($_SESSION[$filename]);
if (($updateOn == 'session' && !$fsession)
|| $updateOn == 'always') {
$fcontent++;
$_SESSION[$filename] = 1;
rewind($myFile);
fwrite($myFile, $fcontent);
}
fclose($myFile);
return $fcontent;
}

?>

<?php include("counter.php"); ?>


(PAGE INCLUDING THE COUNTER:)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Life &amp; Body Balance - sundhed, velvære, massage, zoneterapi, kranie sakral terapi, reiki healing, rosenberg terapi</title>
<link href="LBB.css" rel="stylesheet" type="text/css" />
<!--[if IE 5]>
<style type="text/css">
/* place css box model fixes for IE 5* in this conditional comment */
.twoColFixLtHdr #sidebar1 { width: 230px; }
</style>
<![endif]-->
<!--[if IE]>
<style type="text/css">
/* place css fixes for all versions of IE in this conditional comment */
.twoColFixLtHdr #sidebar1 { padding-top: 30px; }
.twoColFixLtHdr #mainContent { zoom: 1; }
/* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */
</style>
<![endif]-->
<style type="text/css">
<!--
-->
</style>
</head>

<body class="twoColFixLtHdr">
<div class="background">
<div class="background">

<div id="container">
<div id="header">
<table width="100%" border="0" cellpadding="5">
<tr>
<td width="25%"><div align="center"><img src="images/Lavander_large.jpg" width="136" height="90" /></div></td>
<td width="75%"><div align="center">
<h1><span class="logo">Life &amp; Body Balance</span><br />
<span class="navn">Sundhed &amp; Velvære</span></h1>
</div></td>
</tr>
</table>
<!-- end #header --></div>
<div id="sidebar1">
<h3>&nbsp;</h3>
<table width="90%" border="0" align="center" cellpadding="10" cellspacing="5">
<tr>
<td bgcolor="#AA9F80"><div align="center"> <a href="LBB_firma.html" class="linkHvid"><span class="style1">Firmaaftaler</span></a></div></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td bgcolor="#AA9F80" class="linkHvid"><div align="center"> <a href="LBB_hotel.html">Hotelaftaler</a></div></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td bgcolor="#AA9F80"><div align="center"> <a href="LBB_private.html" class="linkHvid"><span class="style1">Private klienter</span></a></div></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td bgcolor="#AA9F80" class="linkHvid"><div align="center"><a href="mailto:life@bodybalance.dk?subject=Mail fra hjemmesiden">Kontakt</a></div></td>
</tr>
<tr>
<td bgcolor="#E0C1FF" class="links">&nbsp;</td>
</tr>
<tr>
<td bgcolor="#E0C1FF" class="links"><div align="center"><img src="images/Massage_large.jpg" width="79" height="52" /></div></td>
</tr>
<tr>
<td bgcolor="#E0C1FF" class="links"><div align="center"><img src="images/Foot_small.jpg" width="79" height="53" /></div></td>
</tr>

<tr>
<td bgcolor="#E0C1FF" class="text"><div align="center">
<p class="readmore">Du er besøgende nr.
<?php PRINT counter('session', 'counter.txt') ?> </p>
</div></td>
</tr>
<tr>
<td bgcolor="#E0C1FF" class="text"><p align="center" class="readmore">Anbefal denne side</p> </td>
</tr>
</table>
</div>
<div id="mainContent">
<table width="100%" border="0" cellspacing="0" cellpadding="10">
<tr>
<td width="66%" rowspan="5" class="table"><p align="center" class="readmore"><img src="images/Anette.JPG" width="103" height="137" /><br />
Anette L. M. Haargaard</p> <span class="text">Life </span>&amp; Body Balance kendetegner netop dét der sættes i fokus ved behandlingerne hos os. Lægeeksamineret i fysiurgisk massage og zoneterapi og med en bred faglig viden indenfor Kranie Sakral Terapi, kostvejledning og råd om motion, sætter vi klienten i fokus. Forskellighed er menneskelighed – derfor giver vi vore behandlinger individuelt i forhold til den enkelte klients behov – og følger behandlingen op med råd til forbedring af den enkeltes sundhedstilstand, f.eks. via motion, kostråd, afstresningsøvelser o.l.
<p>Behandling af myoser og andre ubalancer kan forebygges på mange måder, alt efter behov. Dette gør vi muligt med forskellige hjælpemidler og vejledning, som medarbejderne kan bruge både på arbejdspladsen og privat, i perioderne mellem behandlingerne.</p>
<p>Anette Haargaard, indehaver af Life - &amp; Body Balance, har mange års erhvervserfaring indenfor bl.a. hospitals- og turismesektoren. Endvidere har hun arbejdet med sundhedstjek på arbejdspladsen, og arbejder desuden nogle timer om ugen som behandler i Frederiksberg Hjemmepleje, hvor det er de forskellige personalegrupper, der drager fordel af hendes faglige<br />viden og kompetence. Hos Life &amp; Body Balance er man sikker på at være i fokus i hvert behandlingsforløb, hvor vi laver en mini journal med opdateringer af klientens gener, opfulgt af kostråd og motionsvejledning. </p>
<p>Udvikling frem for alt er vigtigt – derfor opdaterer behandlerne i Life - &amp; Body Balance deres faglige viden via kurser, foredrag og opfølgning af faglitteratur indenfor sundhed og livsstil.</p></td>
<td width="34%" height="20%" class="text"><h2 class="overskriftBrun">Massage</h2>
<p class="readmore"><span class="text">Gennem massage slapper kroppen af, og din stress-tilstand aftager. Når en muskel masseres .</span>...<br />
[<a href="LBB_massage.html">læs mere</a>]</p></td>
</tr>

<tr>
<td width="34%" height="20%"><h2 class="overskriftBrun">Zoneterapi</h2>
<p class="readmore"><span class="text">Zoneterapi er blevet brugt i over 2000 år som en behandlingsform, der virker udrensende og som .... </span><br />
[<a href="LBB_zoneterapi.html">læs mere</a>]</p></td>
</tr>
<tr>
<td width="34%" height="20%"><h2 class="overskriftBrun">Reiki Healing</h2>
<p class="text">Reiki er japansk og betyder universel livsenergi. Reiki healing løsner blokeringer, renser på det fysiske ....<br />
<span class="readmore">[<a href="LBB_reiki.html">læs mere</a>]</span></p></td>
</tr>
<tr>
<td width="34%" height="20%"><h2 class="overskriftBrun">Kranie Sakral Terapi</h2>
<p class="readmore"><span class="text">KST er en manuel, blid og dybdegående behandlingsform, som arbejder med kroppens </span> ....<br />
[<a href="LBB_kranie.html">læs mere</a>]<br />
</p>
</td>
</tr>
<tr>
<td width="34%" height="20%"><h2 class="overskriftBrun">Rosenberg Teknik&reg;</h2>
<p><span class="text">Denne teknik er ligeledes efter Kranie Sakral Terapiens principper. Rosenberg Teknik&reg; ....<br />
</span><span class="readmore">[<a href="LBB_rosenberg.html">læs mere</a>]</span></p></td>
</tr>
</table>
</div>
<!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" />
<div id="footer">
<p align="center"><a href="http://www.kiriwebdesign.com"><img src="images/KIRIWD_logo2delt.gif" width="88" height="31" border="0" /></a></p>
<!-- end #footer --></div>
<!-- end #container -->
</div>
</div>
</div>
</body>
</html>

SPOKMIK
04-07-2008, 02:57 PM
The page including the counter, of course starts with the php-include !

thetestingsite
04-07-2008, 03:22 PM
Do you have correct permissions on counter.txt? That's the only thing I can see, especially as it worked on localhost under windows but not on the live host (probably non-windows).

Hope this helps.

jc_gmk
04-07-2008, 03:41 PM
Yes it sounds like permissions to me.
Maybe set to:

CHMOD 666

The default is usually CHMOD 644 which only allows 'write' by the owner.
666 allows from the group and all other users.

SPOKMIK
04-08-2008, 10:27 AM
How do I verify and change the permission of the counter.txt-file?

thanks

thetestingsite
04-10-2008, 03:50 PM
Using FTP:

- Find the file
- Right click on the file and choose "Properties", "CHMOD", or similar

Using Other:

- I need to know what this other thing that you are using so that I can give you correct instructions.

hope this helps.

SPOKMIK
04-10-2008, 05:51 PM
Hello.

Since I posted my question, I have found the answer. Evidently the counter, wich is created in php, does not work when the page where it is supposed to be shown is created in html. When I changed the index.html to index.php it works as a charm.
But thanks anyway.:)
KIM