What am i doing wrong? (simple php3 + flash counter)
A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: What am i doing wrong? (simple php3 + flash counter)

  1. #1
    What am i doing wrong?

    Please help me, im confused. All seems right but the problem is, the counter shows the number from the textfile, but the counter does not increment every visit.

    Here is what i have


    FLASH FILE
    http://www.samzsitez.com/pic.jpg - its a pic of what i have in general (17kb)
    open above picture first

    action frame # 1 -
    loadVariables ("counter.php3", "_root.digit");

    action frame # 2 -
    loadVariables ("counter.txt", "_root.digit");

    action frame # 12 -
    gotoAndPlay (2);


    PHP3 FILE

    <?php $fd = fopen("counter.txt", "w");
    fwrite($fd, "count=$count++");
    fclose($fd); ?>


    TXT FILE

    count=1


    My text fields have the correct variables. It loads the number no problem. I think its the php3 file since my counter.txt doesnt increment.

    i have chmod the files correctly.

    What am i doing wrong? can you help me?

  2. #2
    Senior Member
    Join Date
    Feb 2001
    Posts
    475
    did you look into the counter.txt file? is there the correct number, or does your php not update the counter?

    if the number is correct there's the problem of cached data by the browser - so your browser always shows the content of the cached counter.txt and not the newest version - to work around that:

    loadVariables ("counter.txt?dummy=" + random (100000), "_root.digit");

    this way the browser thinks it is a "different" file and must be reloaded.

    Yours
    HTD

  3. #3
    Thank for that info, but unfortunatel that did dot correct my problem.

    i think theres something wrong with my php script. my extension is php3, not php so perhaps im using some php code in there, not php3

  4. #4
    Moderator
    Join Date
    Feb 2001
    Posts
    13,044
    Hi,

    you are asking for php to update the vars
    in the next frame (maybe 1/12 of a second later) you are asking for the updated text file
    less than a second later you are repeating the cycle
    ... php on my server would not run that fast

    To see whether the php works, open both the txt file and the php in browser - also the text file needs to be 666 on some servers (certainly not 755)

    Musicman

  5. #5
    Something i forgot to tell you

    i have set my fps to 1 every second.

    This gives enough time for the php script to function on my server.

    hope you can help further

  6. #6
    is it also possible to run php3 files on my own computer, even if its just win98?

    I tried downloading the required files from php.net, if doenst seem to work

  7. #7
    also, i dont think time of php processing is a factor since the flash file reloads the variable text file as a loop anyways, so it would update the counter sooner or later right?

  8. #8
    Senior Member
    Join Date
    Feb 2001
    Posts
    475
    I don't know how you run PHP on your machine, but if you use PHP 4 and apache all you have to do is tell apache to interpret php3 files like php 4 files.

    add this to your httpd.conf:
    AddType application/x-httpd-php .php3

    Ok - are the correct values stored in the .txt file or not? if the .txt isn't updated, it can't work for flash then. can you post the contents of counter.txt and the core code of the .php3 file for writing the info to the textfile?

    Yours
    HTD

  9. #9
    i wrote the code already earlier in this thread. My fist question has it, together with the actionscripts

  10. #10
    Senior Member
    Join Date
    Feb 2001
    Posts
    475
    oops - sorry, didn't see it

    <?php $fd = fopen("counter.txt", "w");
    fwrite($fd, "count=$count++");
    fclose($fd); ?>

    where do you get the value for $count ?? does the counter work when you call your php file from the browser and not from flash?

    this would be my code

    <?php
    $count = 1;
    $count++;
    $fd = fopen("counter.txt", "w");
    fwrite($fd, "count=".$count);
    fclose($fd);
    ?>

    replace the "count=1" code with a routine that reads the actual state from the file...
    Yours
    HTD

  11. #11

    Smile

    thanks, just so i wont have trouble, now and for the furute, can you please code out this "routine" for me?
    thanks alot

  12. #12
    Senior Member
    Join Date
    Feb 2001
    Posts
    475
    hm - my code has a different approach than yours now... i'd store the counter in a text file and let php do the output for flash:

    counter.php:

    <?php
    <?php $fd = fopen("counter.txt", "r");
    $number = fgets($fd, 1024);
    fclose($fd);

    $number++;
    echo 'count='.$number;

    ?>

    now in actionscript:

    loadVariables ("counter.php", "_root.digit");

    that's all - note that in the counter.txt there's only the current number of hits saved, nothing else. in my code php simulates the text-file by echoing the correct syntax for a flash variable file.
    Yours
    HTD

  13. #13
    Moderator
    Join Date
    Feb 2001
    Posts
    13,044
    Hi,

    try this
    <?php
    $fp = fopen("counter.txt", "r");
    $data = fgets($fp, 100);
    fclose($fp);
    if(ereg("counter=([0-9]+)", $data[0], $found))
    { $counter = $found[1] + 1;
    $fp = fopen("counter.txt", "w");
    fputs($fp, "counter=$counter");
    fclose($fp);
    } // otherwise might be wrong file

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width


HTML5 Development Center

Poll by Flashkit.com