Yes, but what if you refresh the page?
Or type in the address bar index.php and press enter, i think it will be
increased?

Radovan

"J.Veenhuijsen" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> This is working on my test system.
>
> <?
> session_start();
> if ( ! isset($_SESSION['count']) )
> {
>    $fp=fopen("./counter.txt","r");
>    $_SESSION['count']=fread($fp,5);
>    fclose($fp);
>    $_SESSION['count']++;
>    $cnt=$_SESSION['count'];
>    $fp=fopen("./counter.txt","w");
>    fwrite($fp,$cnt);
>    fclose($fp);
> }
> $c= $_SESSION['count'];
> print "Visited: .$c.<BR>";
> ?>
>
>
> Jochem
>
>
> Cybot wrote:
> > CORRECT use $_SESSION !
> >
> > counter.php:
> > <?
> > if ( ! isset($_SESSION['count']) )
> > {
> >   $fp=fopen("counter.txt","r");
> >   $_SESSION['count']=fread($fp);
> >   fclose($fp);
> >   $_SESSION['count']++;
> > }
> > print "Visited: $_SESSION['count']<BR>";
> > ?>
> >
> > index.php
> > <?
> > session_start();
> > print "Simple page<BR>";
> > include("counter.php");
> > ?>
> >
> >
> > Radovan Radic wrote:
> >
> >>> Hi
> >>>
> >>> I want to add simple counter on my index.php page.
> >>>
> >>> counter.php:
> >>> <?
> >>> if (!session_is_registered("counter"))
> >>> {
> >>>   $fp=fopen("counter.txt","r");
> >>>   $counter=fread($fp);
> >>>   fclose($fp);
> >>>   $counter++;
> >>>   session_register("counter");
> >>> }
> >>> print "Visited: $counter<BR>";
> >>> ?>
> >>>
> >>> index.php
> >>> <?
> >>> session_start();
> >>> print "Simple page<BR>";
> >>> include("counter.php");
> >>> ?>
> >>>
> >>> This should work, but when someone refreshes index.php page, counter
is
> >>> increased! How can i stop it?
> >>>
> >>> Thx,
> >>> Radovan
> >>>
> >>>
> >>
> >
>



-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to