Re: Counter problems!
| From: | Radovan Radic | Date: | Thu, 30 Jan 2003 14:23:10 +0000 |
| Subject: | Re: Counter problems! | ||
| References: | 1 2 3 4 5 6 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-18235@lists.php.net to get a copy of this message | ||
Thank you, i didnt try it yet and sorry - i assumed it will work wrong.
Radovan
"J Veenhuijsen" <info@solid-digital.nl> wrote in message
news:3E392C4E.80209@solid-digital.nl...
> I tested that and the counter does not increase when i hit
> the refresh button or press enter in the adressbar.
> It only increases when i quit the explorer and reopen the same link
> afterwards. Which is ofcourse a new visit because the session is
> distroyed when closing the browser.
>
> Jochem
>
>
> Radovan Radic wrote:
> > 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" <info@solid-digital.nl> wrote in message
> > news:3E38DEF0.9070904@solid-digital.nl...
> >
> >>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
> >>>>>
> >>>>>
> >>>>
> >
> >
>
>