# PHP Counter is not working :(

**URL:** <https://forum.kirupa.com/t/php-counter-is-not-working/34090>\
**Category:** programming\
**Created:** [October 28, 2003, 3:10am UTC](https://forum.kirupa.com/t/php-counter-is-not-working/34090 "2003-10-28T03:10:46Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![PaulD](https://avatars.discourse-cdn.com/v4/letter/p/958977/32.png) [@PaulD](https://forum.kirupa.com/u/PaulD)\
**Post date:** [October 28, 2003, 3:10am UTC](https://forum.kirupa.com/t/php-counter-is-not-working/34090/1 "2003-10-28T03:10:46Z")

</div>

Hi everyone

I have found this PHP Counter on the net but when applied to my Webpage it does not work.

Just wondering if anyone can take a look if they get a spare second or two.

I have attached the file dynamic\_counter.zip

this is what it looks like in action on my website  
[http://www.dicksoncreativedesigns.com](http://www.dicksoncreativedesigns.com)

as you can see the counter is not displaying ☹

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 28, 2003, 10:07am UTC](https://forum.kirupa.com/t/php-counter-is-not-working/34090/2 "2003-10-28T10:07:30Z")

</div>

Does your host support PHP?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 28, 2003, 10:24am UTC](https://forum.kirupa.com/t/php-counter-is-not-working/34090/3 "2003-10-28T10:24:02Z")

</div>

Yes it does support PHP, I have a contact form using PHP & that works ok.

Wierd :h:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 28, 2003, 10:54am UTC](https://forum.kirupa.com/t/php-counter-is-not-working/34090/4 "2003-10-28T10:54:35Z")

</div>

Hmm…there aren’t any instructions with that thing, but I think you might have to CHMOD the text file in order for it to work.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 28, 2003, 11:08am UTC](https://forum.kirupa.com/t/php-counter-is-not-working/34090/5 "2003-10-28T11:08:39Z")

</div>

CHMOD the text file. How do I do that?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 28, 2003, 11:12am UTC](https://forum.kirupa.com/t/php-counter-is-not-working/34090/6 "2003-10-28T11:12:12Z")

</div>

Some FTP programs has that feature.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 28, 2003, 11:20am UTC](https://forum.kirupa.com/t/php-counter-is-not-working/34090/7 "2003-10-28T11:20:31Z")

</div>

I’m using FlashFXP FTP Program, do I have to tell the txt file to be CHMOD? What is CHMOD?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 28, 2003, 11:22am UTC](https://forum.kirupa.com/t/php-counter-is-not-working/34090/8 "2003-10-28T11:22:17Z")

</div>

Yes, you’ll need to do it through whichever FTP program you have if it has that feature.

CHMOD basically allows the the information in the text file to be read or written over.

EDIT: I also believe you’ll need to CHMOD it 777, but I’m not sure.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 28, 2003, 12:06pm UTC](https://forum.kirupa.com/t/php-counter-is-not-working/34090/9 "2003-10-28T12:06:17Z")

</div>

ok I will see what I can do, thx for the info!!!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 28, 2003, 1:19pm UTC](https://forum.kirupa.com/t/php-counter-is-not-working/34090/10 "2003-10-28T13:19:38Z")

</div>

Ok I managed to work out what I was doing wrong & thought I would let you know.

I needed to change the file permissions on my web server to READ,WRITE,EXECUTE.

The Chmod php file was 665 (-rw-rw-r-x) and the text file was 666 (-rw-rw-rw-).

Thanks for your help 😉

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 28, 2003, 4:04pm UTC](https://forum.kirupa.com/t/php-counter-is-not-working/34090/11 "2003-10-28T16:04:41Z")

</div>

I was using PHP3 which I dont think the server supports, hopefully by updating the actionscript to PHP will allow the counter to function.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 28, 2003, 4:09pm UTC](https://forum.kirupa.com/t/php-counter-is-not-working/34090/12 "2003-10-28T16:09:50Z")

</div>

\*\*\*\* it did not work ☹ wierd

Im referencing from this tutorial

[http://www.actionscript.org/tutorials/intermediate/dynamic\_counter\_php3/index.shtml](http://www.actionscript.org/tutorials/intermediate/dynamic_counter_php3/index.shtml)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 28, 2003, 7:21pm UTC](https://forum.kirupa.com/t/php-counter-is-not-working/34090/13 "2003-10-28T19:21:58Z")

</div>

For future reference, flashfxp chmod shortcut is ctrl+o or just right click the file and select CHMOD (right clicking also shows the shortcut). Since you changed the file extension be sure to re-read the code and be sure that all referenced files are .php now and not .php3

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 29, 2003, 4:14pm UTC](https://forum.kirupa.com/t/php-counter-is-not-working/34090/14 "2003-10-29T16:14:30Z")

</div>

Ok I have changed my PHP script to the following:

```php

<?php $fd = fopen("counter.txt", "w");
fwrite($fd, "count=".$_GET['count']."&loaded=1"); 
fclose($fd); ?>
<p>Counter incremented: value is now <?php echo $_GET['count'];?>

```

Still does not seem to be functioning

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 29, 2003, 5:41pm UTC](https://forum.kirupa.com/t/php-counter-is-not-working/34090/15 "2003-10-29T17:41:42Z")

</div>

Some things to try out… I use text files all the time…

First, don’t you need to read what count to increment before you actually can increment it?

I’ll make you a quick script that should work for ya…

Here…

```php

<?php
$rawData = file("counter.txt");
$rawData[0] = rtrim(rawData[0]);
$numData = sprintf("%d", $rawData[0]);
$numData++;

unlink("counter.txt");
$filePointer = fopen("counter.txt", "w");
$strData = sprintf("%s", $numData);
fputs($filePointer, "$strData
");
fclose($filePointer);
?>

```

It may look like alot for a simple counter. But this will ensure that no variable changeovers get in the way of placing a better counter in your system. It automatically updates it’s numbers so it’s alot easier.

I don’t know why they had the GET global variable set used in your example… That would only work everytime someone sent a form or something… Weird.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 29, 2003, 5:57pm UTC](https://forum.kirupa.com/t/php-counter-is-not-working/34090/16 "2003-10-29T17:57:01Z")

</div>

@ Bhuddamarz

Here is the location of the source files I am currently using.

\< [http://www.dicksoncreativedesigns.com.temp/counter.zip](http://www.dicksoncreativedesigns.com.temp/counter.zip) \>

Do you suggest I change the “counter.php” scripting to the one you have specified below?

I will give it a try…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 29, 2003, 6:16pm UTC](https://forum.kirupa.com/t/php-counter-is-not-working/34090/17 "2003-10-29T18:16:12Z")

</div>

It still did not work even with your modified script. Thank you for trying.

I’m think that there is something wrong with this script on Frame1 of my FLA file.

[AS]  
if (startup eq “”) {  
startup = “Run Already”;  
loadVariables(“counter.txt?” add random(2000), “/counter”);  
}  
[/AS]

shouldn’t the “/counter” be “/counter.php” ?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 29, 2003, 7:14pm UTC](https://forum.kirupa.com/t/php-counter-is-not-working/34090/18 "2003-10-29T19:14:10Z")

</div>

Ohhhhh! You want this made for flash… _lmfao_… Oh \*\*\*\* man… Hold on… lemme get you some newer script… _lmao_… Sorry…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 29, 2003, 7:26pm UTC](https://forum.kirupa.com/t/php-counter-is-not-working/34090/19 "2003-10-29T19:26:31Z")

</div>

Paul, please excuse Marlin here, he’s been smoking too much butt crack lately. :beam:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 29, 2003, 7:37pm UTC](https://forum.kirupa.com/t/php-counter-is-not-working/34090/20 "2003-10-29T19:37:51Z")

</div>

if (startup eq “”)

Exactly what does this line here do? Is this a part of the new MX 2004 or is it just wrongly written?

Ohhh NEver mind… It’s a eq… _lmao_… Actually… Why don’t you do this…

```php

if(startup == FALSE)
{
     startup = TRUE;
     loadVariables("counter.txt", "_root.countTarget");
}

```

The countTarget should be a textfield located on your movie… Should be in Frame 1 along with this coding. name it countTarget. On the text field, you should also change the variable setting as well… Give it a name of : someCounter.

Also… Change around the php code I gave you… One tiny bit and save it as this…

```php

<?php
 $rawData = file("counter.txt");
 $rawData[0] = rtrim(rawData[0]);
 $numData = sprintf("%d", $rawData[0]);
 $numData++; 

 unlink("counter.txt");
 $filePointer = fopen("counter.txt", "w");
 $strData = sprintf("someCounter=%s", $numData);
 fputs($filePointer, "$strData
");
 fclose($filePointer);
?>

```

See if that works out for you… I’m sorry if it doesn’t… I haven’t worked with loadVariables in a while 😃

[Next page](https://forum.kirupa.com/t/php-counter-is-not-working/34090.md?page=2)
