Can't get $cnt++ to work

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Wilfred Johnson

    Can't get $cnt++ to work


    I have a little simple hit counter. It works if I replace $cnt++;
    with #cnt = $cnt + 1;
    I can't see why this doesn't work. Any ideas?


    if(file_exists( "counter.da t")) {
    $f = fopen("counter. dat", "r");
    $cnt = fread($f, 10);
    //echo "\n", "count 1 = ", $cnt, "\n";
    fclose($f);
    //$cnt++; DOESN'T WORK!!!
    $cnt = $cnt + 1;
    //echo "\n", "count 2 = ", $cnt, "\n";
    $f = fopen("counter. dat", "w");
    fwrite($f, $cnt);
    fclose($f);
    printf("\n%d people have visited this page\n", $cnt);
    }

    thanks,
    Wilfred


  • Anders K. Madsen

    #2
    Re: Can't get $cnt++ to work

    On Tue, 27 Jul 2004 19:01:36 -0400
    Wilfred Johnson <wj5437@yahoo.c om> wrote:
    [color=blue]
    >
    > I have a little simple hit counter. It works if I replace $cnt++;
    > with #cnt = $cnt + 1;
    > I can't see why this doesn't work. Any ideas?
    >[/color]

    What happens if you replace $cnt++ with ++$cnt?

    This might not work, just an idea...

    Madsen

    --
    Anders K. Madsen --- http://lillesvin.linux.dk

    "There are 10 types of people in the world.
    Those who understand binary - and those who don't."

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.4 (GNU/Linux)

    iD8DBQFBBuZolNH Je/JASHcRAg2SAJ0eU/e3kidGrBoe92fbF lOxqSGsUACfeTRV
    hRUEq2cil4if7QU 4iehQBt0=
    =urf/
    -----END PGP SIGNATURE-----

    Comment

    • Guest's Avatar

      #3
      Re: Can't get $cnt++ to work

      > I have a little simple hit counter. It works if I replace $cnt++;[color=blue]
      > with #cnt = $cnt + 1;
      > I can't see why this doesn't work. Any ideas?
      >
      > $cnt = fread($f, 10);
      > //echo "\n", "count 1 = ", $cnt, "\n";
      > fclose($f);
      > //$cnt++; DOESN'T WORK!!![/color]

      Please use the following notation and your $cnt++ will work -
      $cnt = (int) fread($f, 10);

      _______________ _______________ ______
      Wil Moore III, MCP | Integrations Specialist


      Comment

      • Anders K. Madsen

        #4
        Re: Can't get $cnt++ to work

        On Tue, 27 Jul 2004 16:38:41 -0700
        <laidbak69@hotm ail.com> wrote:
        [color=blue][color=green]
        > > I have a little simple hit counter. It works if I replace $cnt++;
        > > with #cnt = $cnt + 1;
        > > I can't see why this doesn't work. Any ideas?
        > >
        > > $cnt = fread($f, 10);
        > > //echo "\n", "count 1 = ", $cnt, "\n";
        > > fclose($f);
        > > //$cnt++; DOESN'T WORK!!![/color]
        >
        > Please use the following notation and your $cnt++ will work -
        > $cnt = (int) fread($f, 10);
        >[/color]

        Oh yeah, of course!
        Disregard my answer earlier in this thread, it sucks!

        So much for PHPs implicit types! :-p

        --
        Anders K. Madsen --- http://lillesvin.linux.dk

        "There are 10 types of people in the world.
        Those who understand binary - and those who don't."

        -----BEGIN PGP SIGNATURE-----
        Version: GnuPG v1.2.4 (GNU/Linux)

        iD8DBQFBBuvIlNH Je/JASHcRAqhhAJoCv Da1zMjYauov1Lu8 iBjYQ3UUtQCfTfG Q
        g5M7h2MZOaWscWa 1b/HEf6U=
        =w7pP
        -----END PGP SIGNATURE-----

        Comment

        • Rainbow News Service

          #5
          Re: Can't get $cnt++ to work

          Wilfred Johnson wrote:[color=blue]
          > I have a little simple hit counter. It works if I replace $cnt++;
          > with #cnt = $cnt + 1;
          > I can't see why this doesn't work. Any ideas?
          >
          >
          > if(file_exists( "counter.da t")) {
          > $f = fopen("counter. dat", "r");
          > $cnt = fread($f, 10);
          > //echo "\n", "count 1 = ", $cnt, "\n";
          > fclose($f);
          > //$cnt++; DOESN'T WORK!!!
          > $cnt = $cnt + 1;
          > //echo "\n", "count 2 = ", $cnt, "\n";
          > $f = fopen("counter. dat", "w");
          > fwrite($f, $cnt);
          > fclose($f);
          > printf("\n%d people have visited this page\n", $cnt);
          > }
          >
          > thanks,
          > Wilfred
          >
          >[/color]
          I put it on my server, it works fine:

          <?
          if(file_exists( "counter.da t")) {
          $f = fopen("counter. dat", "r");
          $cnt = fread($f, 10);
          //echo "\n", "count 1 = ", $cnt, "\n";
          fclose($f);
          $cnt++;
          //$cnt = $cnt + 1;
          //echo "\n", "count 2 = ", $cnt, "\n";
          $f = fopen("counter. dat", "w");
          fwrite($f, $cnt);
          fclose($f);
          printf("\n%d people have visited this page\n", $cnt);
          }
          ?>

          If that doesn't work, then you need to break the code up into simpler
          steps to find out why.

          start with:
          <?
          $cnt=8;
          $cnt++;
          echo $cnt;

          ?>
          If it says "9", which would be correct, then there's probably something
          wrong with your original code. Just reconstruct the original code a
          piece at a time until the error reappears.

          red

          Comment

          • Wilfred Johnson

            #6
            Re: Can't get $cnt++ to work


            I did cast the fread return to an int and it now works now. My php
            is on linux and is version 4.3.7.


            On Wed, 28 Jul 2004 03:31:30 GMT, Rainbow News Service
            <news@rainbowfa mily.info> wrote:
            [color=blue]
            >Wilfred Johnson wrote:[color=green]
            >> I have a little simple hit counter. It works if I replace $cnt++;
            >> with #cnt = $cnt + 1;
            >> I can't see why this doesn't work. Any ideas?
            >>
            >>
            >> if(file_exists( "counter.da t")) {
            >> $f = fopen("counter. dat", "r");
            >> $cnt = fread($f, 10);
            >> //echo "\n", "count 1 = ", $cnt, "\n";
            >> fclose($f);
            >> //$cnt++; DOESN'T WORK!!!
            >> $cnt = $cnt + 1;
            >> //echo "\n", "count 2 = ", $cnt, "\n";
            >> $f = fopen("counter. dat", "w");
            >> fwrite($f, $cnt);
            >> fclose($f);
            >> printf("\n%d people have visited this page\n", $cnt);
            >> }
            >>
            >> thanks,
            >> Wilfred
            >>
            >>[/color]
            >I put it on my server, it works fine:
            >
            ><?
            >if(file_exists ("counter.dat") ) {
            > $f = fopen("counter. dat", "r");
            > $cnt = fread($f, 10);
            > //echo "\n", "count 1 = ", $cnt, "\n";
            > fclose($f);
            > $cnt++;
            > //$cnt = $cnt + 1;
            > //echo "\n", "count 2 = ", $cnt, "\n";
            > $f = fopen("counter. dat", "w");
            > fwrite($f, $cnt);
            > fclose($f);
            > printf("\n%d people have visited this page\n", $cnt);
            >}
            >?>
            >
            >If that doesn't work, then you need to break the code up into simpler
            >steps to find out why.
            >
            >start with:
            ><?
            >$cnt=8;
            >$cnt++;
            >echo $cnt;
            >
            >?>
            >If it says "9", which would be correct, then there's probably something
            >wrong with your original code. Just reconstruct the original code a
            >piece at a time until the error reappears.
            >
            >red[/color]

            Comment

            • Pjotr Wedersteers

              #7
              Re: Can't get $cnt++ to work

              Anders K. Madsen wrote:

              Could you check your news settings, Anders ? All your contributions appear
              as attached files.
              TY
              Pjotr


              Comment

              • Ian.H

                #8
                Re: Can't get $cnt++ to work

                On Wed, 28 Jul 2004 15:22:06 +0200, Pjotr Wedersteers wrote:
                [color=blue]
                > Anders K. Madsen wrote:
                >
                > Could you check your news settings, Anders ? All your contributions appear
                > as attached files.
                > TY
                > Pjotr[/color]


                They all appear fine to me...


                X-Newsreader: Microsoft Outlook Express 6.00.2800.1437


                I suspect the news issue is your client ;)



                Regards,

                Ian


                --
                Ian.H
                digiServ Network
                London, UK


                Comment

                • Anders K. Madsen

                  #9
                  Re: Can't get $cnt++ to work

                  -----BEGIN PGP SIGNED MESSAGE-----
                  Hash: SHA1

                  On Wed, 28 Jul 2004 15:22:06 +0200
                  "Pjotr Wedersteers" <x33159@westert erp.com> wrote:
                  [color=blue]
                  > Could you check your news settings, Anders ? All your contributions
                  > appear as attached files.[/color]

                  Of course... I've heard complaints about this before, but alas, I don't
                  know what causes it.
                  I'm trying a new setting now, so if it's alright, please tell me so.

                  I'm using Sylpheed-Claws (as you can see in my X-Mailer header), so if
                  anyone knows how to make it _not_ attach the messages I'd be very
                  delighted to hear it.

                  Best regards
                  Madsen

                  - --
                  Anders K. Madsen --- http://lillesvin.linux.dk

                  "There are 10 types of people in the world.
                  Those who understand binary - and those who don't."
                  -----BEGIN PGP SIGNATURE-----
                  Version: GnuPG v1.2.4 (GNU/Linux)

                  iD8DBQFBB7GLlNH Je/JASHcRAta5AJ4py n5isgexxDNuoS2g Vj/8ciqsZwCdFfL1
                  A7YwDMaEgfFKKJu vbHgZjjE=
                  =bMzP
                  -----END PGP SIGNATURE-----

                  Comment

                  • Cafer Simsek

                    #10
                    Re: Can't get $cnt++ to work

                    I think you may try that:

                    $cnt=trim($cnt) ;
                    $cnt++;


                    Wilfred Johnson <wj5437@yahoo.c om> wrote in message news:<qhndg01d9 kleg120cebvab6g rc1bgqms63@4ax. com>...[color=blue]
                    > I have a little simple hit counter. It works if I replace $cnt++;
                    > with #cnt = $cnt + 1;
                    > I can't see why this doesn't work. Any ideas?
                    >
                    >
                    > if(file_exists( "counter.da t")) {
                    > $f = fopen("counter. dat", "r");
                    > $cnt = fread($f, 10);
                    > //echo "\n", "count 1 = ", $cnt, "\n";
                    > fclose($f);
                    > //$cnt++; DOESN'T WORK!!!
                    > $cnt = $cnt + 1;
                    > //echo "\n", "count 2 = ", $cnt, "\n";
                    > $f = fopen("counter. dat", "w");
                    > fwrite($f, $cnt);
                    > fclose($f);
                    > printf("\n%d people have visited this page\n", $cnt);
                    > }
                    >
                    > thanks,
                    > Wilfred[/color]

                    Comment

                    • Pjotr Wedersteers

                      #11
                      Re: Can't get $cnt++ to work

                      Anders K. Madsen wrote:[color=blue]
                      > -----BEGIN PGP SIGNED MESSAGE-----
                      > Hash: SHA1
                      >
                      > On Wed, 28 Jul 2004 15:22:06 +0200
                      > "Pjotr Wedersteers" <x33159@westert erp.com> wrote:
                      >[color=green]
                      >> Could you check your news settings, Anders ? All your contributions
                      >> appear as attached files.[/color]
                      >
                      > Of course... I've heard complaints about this before, but alas, I
                      > don't know what causes it.
                      > I'm trying a new setting now, so if it's alright, please tell me so.
                      >
                      > I'm using Sylpheed-Claws (as you can see in my X-Mailer header), so if
                      > anyone knows how to make it _not_ attach the messages I'd be very
                      > delighted to hear it.
                      >
                      > Best regards
                      > Madsen
                      >
                      > - --
                      > Anders K. Madsen --- http://lillesvin.linux.dk
                      >
                      > "There are 10 types of people in the world.
                      > Those who understand binary - and those who don't."
                      > -----BEGIN PGP SIGNATURE-----
                      > Version: GnuPG v1.2.4 (GNU/Linux)
                      >
                      > iD8DBQFBB7GLlNH Je/JASHcRAta5AJ4py n5isgexxDNuoS2g Vj/8ciqsZwCdFfL1
                      > A7YwDMaEgfFKKJu vbHgZjjE=
                      > =bMzP
                      > -----END PGP SIGNATURE-----[/color]

                      Sorry, it may well be my newsreader which has a problem with some formats (I
                      never thought OE was the perfect newsreader). But now it appears fine here,
                      ty!

                      Pjotr


                      Comment

                      • Anders K. Madsen

                        #12
                        Re: Can't get $cnt++ to work

                        -----BEGIN PGP SIGNED MESSAGE-----
                        Hash: SHA1

                        On Wed, 28 Jul 2004 17:23:33 +0200
                        "Pjotr Wedersteers" <x33159@westert erp.com> wrote:
                        [color=blue]
                        > Sorry, it may well be my newsreader which has a problem with some
                        > formats (I never thought OE was the perfect newsreader). But now it
                        > appears fine here, ty!
                        >[/color]

                        Yeah, the other people complaining about my posts being attachments also
                        use OE. But I guess I'll just use the inline PGP signature then. Unless
                        somebody tells me that it is highly non-standard.

                        Best regards,
                        Madsen


                        - --
                        Anders K. Madsen --- http://lillesvin.linux.dk

                        "There are 10 types of people in the world.
                        Those who understand binary - and those who don't."

                        -----BEGIN PGP SIGNATURE-----
                        Version: GnuPG v1.2.4 (GNU/Linux)

                        iD8DBQFBB8kblNH Je/JASHcRAgZPAJ4+n 7x0fDU99jVNxzSv cW80gYP0NQCfX3k T
                        wb6WOPlf873WX+o dnr7XQDk=
                        =BZev
                        -----END PGP SIGNATURE-----

                        Comment

                        • Ian.H

                          #13
                          Re: Can't get $cnt++ to work

                          On Wed, 28 Jul 2004 16:00:43 +0200, Anders K. Madsen wrote:
                          [color=blue]
                          > -----BEGIN PGP SIGNED MESSAGE-----
                          > Hash: SHA1
                          >
                          > On Wed, 28 Jul 2004 15:22:06 +0200
                          > "Pjotr Wedersteers" <x33159@westert erp.com> wrote:
                          >[color=green]
                          >> Could you check your news settings, Anders ? All your contributions
                          >> appear as attached files.[/color]
                          >
                          > Of course... I've heard complaints about this before, but alas, I don't
                          > know what causes it.
                          > I'm trying a new setting now, so if it's alright, please tell me so.[/color]


                          [ snip ]


                          Heh.. now wait for the other complaints Anders.. about your sig exceeding
                          4 lines ;)

                          FWIW.. I'm not complaining.. the inline version works fine reading it in
                          Pan (windoze and FreeBSD) and the signed single version also works.. but
                          from past experience, people dislike this [sigh]. I used to use PGP to
                          post to most groups too.. as I used to frequent alt.comp.virus regularly..
                          in some groups more than others, signing posts made sense.. and searching
                          google for my unmunged address in this post will reveal some idiotic posts
                          to spam, virus and some suicide groups courtesy of some kid who didn't
                          like a response I made (kids will be kids I guess) which outlines why I
                          personally think signing has some benefit.. but I ended up dropping the
                          lot to keep the peace.

                          Hopefully you wont get hassled too.. but keep your fireproof suit handy =)



                          Regards,

                          Ian

                          --
                          Ian.H
                          digiServ Network
                          London, UK


                          Comment

                          • Geoff Berrow

                            #14
                            Re: Can't get $cnt++ to work

                            I noticed that Message-ID:
                            <pan.2004.07.28 .16.12.11.75000 0@bubbleboy.dig iserv.net> from Ian.H
                            contained the following:
                            [color=blue]
                            >which outlines why I
                            >personally think signing has some benefit.. but I ended up dropping the
                            >lot to keep the peace.[/color]

                            As if anyone could mistake your style...<g>

                            --
                            Geoff Berrow (put thecat out to email)
                            It's only Usenet, no one dies.
                            My opinions, not the committee's, mine.
                            Simple RFDs http://www.ckdog.co.uk/rfdmaker/

                            Comment

                            • Anders K. Madsen

                              #15
                              Re: Can't get $cnt++ to work

                              -----BEGIN PGP SIGNED MESSAGE-----
                              Hash: SHA1

                              On Wed, 28 Jul 2004 16:13:23 GMT
                              "Ian.H" <ian@WINDOZEdig iserv.net> wrote:
                              [color=blue]
                              > On Wed, 28 Jul 2004 16:00:43 +0200, Anders K. Madsen wrote:
                              >[color=green]
                              > > -----BEGIN PGP SIGNED MESSAGE-----
                              > > Hash: SHA1
                              > >
                              > > On Wed, 28 Jul 2004 15:22:06 +0200
                              > > "Pjotr Wedersteers" <x33159@westert erp.com> wrote:
                              > >[color=darkred]
                              > >> Could you check your news settings, Anders ? All your contributions
                              > >> appear as attached files.[/color]
                              > >
                              > > Of course... I've heard complaints about this before, but alas, I
                              > > don't know what causes it.
                              > > I'm trying a new setting now, so if it's alright, please tell me so.[/color]
                              >
                              >
                              > [ snip ]
                              >
                              >
                              > Heh.. now wait for the other complaints Anders.. about your sig
                              > exceeding 4 lines ;)
                              >
                              > FWIW.. I'm not complaining.. the inline version works fine reading it
                              > in Pan (windoze and FreeBSD) and the signed single version also
                              > works.. but from past experience, people dislike this [sigh]. I used
                              > to use PGP to post to most groups too.. as I used to frequent
                              > alt.comp.virus regularly.. in some groups more than others, signing
                              > posts made sense.. and searching google for my unmunged address in
                              > this post will reveal some idiotic posts to spam, virus and some
                              > suicide groups courtesy of some kid who didn't like a response I made
                              > (kids will be kids I guess) which outlines why I personally think
                              > signing has some benefit.. but I ended up dropping the lot to keep the
                              > peace.
                              >[/color]

                              Hmm, I'd be very sorry to drop my PGP signature. (Are there no space for
                              security on Usenet?)
                              I've only begun using it recently and so far, the only complaint I've
                              had not being about my messages being attached in OE rather than an
                              actual RFC-822 mail, is one guy who questioned the actual usefulness of
                              PGP signatures on Usenet.
                              [color=blue]
                              > Hopefully you wont get hassled too.. but keep your fireproof suit
                              > handy =)
                              >[/color]

                              Hehe, I will. :) Thanks!

                              Madsen

                              - --
                              Anders K. Madsen --- http://lillesvin.linux.dk

                              "There are 10 types of people in the world.
                              Those who understand binary - and those who don't."

                              -----BEGIN PGP SIGNATURE-----
                              Version: GnuPG v1.2.4 (GNU/Linux)

                              iD8DBQFBB+dilNH Je/JASHcRAt8vAJ9gN 7oKYr1UQmWoY/laAfN/+Hbp6QCfTu23
                              YApy4LNtmbMbj1Y JdwifnRY=
                              =Rm9P
                              -----END PGP SIGNATURE-----

                              Comment

                              Working...