Welcome, Guest
  • Author Topic: Php flash counter questions  (Read 16429 times)

    Metal Fusion

    • Guest
    Php flash counter questions
    « on: 12/20/02, 23:08 »
    hi
    newbie here
    I have this problem:
    My flash counter is a movie clip that is wethin another movie clip.
    How do i set this in the php file?

    Second question:
    The latest version of php which i have installed 4.2.3 requires you to use this to display variable $_POST etc.
    How do i modify that for teh script??

    Thanks

    Flash-db

    • Administrator
    • Systems Administrator
    • *****
    • Posts: 1876
      • View Profile
      • Flash-db.com
    Re:Php flash counter questions
    « Reply #1 on: 12/21/02, 01:43 »
    Surprisingly you should not have to change anything for this one.  The $_POST or $HTTP_POST_VARS['myvar'] is only needed if variables are being sent from the Flash movie to the PHP script.  In this case you do not have to worry since no variables are being sent from the Flash movie to the PHP script.  Basically the Flash movie calls the script and it then updates a text file (increments the current number by one) - in effect counting the number of times the file has been called (which is also the number of times the movie has been visited).  

    Here is the PHP script.

    Code: [Select]

    <?php<br><br>$filename "PHPCounter.txt";  // text file to write to (make sure to change permissions).<br><br>// Opens a new file for writing to (fp is short for file pointer, although it can be named anything).<br>// this reads the current count from the file.<br>$fp        = fopen( $filename,"r"); <br>$Old      = fread($fp, 100); <br>fclose( $fp ); <br><br>// Split the current data where there is an equal sign<br>$Old = split ("=", $Old, 5);<br><br>// Increment the old count from the file by 1.<br>$NewCount = $Old[1] + '1';<br><br>$New = "Count=$NewCount";<br><br>// Open the same file for writing (w) and write the new count.<br>$fp = fopen( $filename,"w");<br>if (flock($fp, 2)) { <br>fwrite($fp, $New, 100); }<br>fclose( $fp ); <br><br>// Finally print the new count out so the flash movie can read the number in.<br>print "Count=$NewCount";<br><br>?>


    The flock part is an attempt at locking the file so it can only be written to once - although you can get much more complicated with that part.

    Hope that helps.
    Flash-DB

    Musicman

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 2685
      • View Profile
      • Email
    Re:Php flash counter questions
    « Reply #2 on: 12/21/02, 03:49 »
    Hi,

    this is the same script, rewritten to do locking correctly...

    Code: [Select]

    <?php<br><br>$filename "PHPCounter.txt";  // text file to write to (make sure to change permissions).<br><br>// Opens a new file for first reading, then writing to (fp is short for file pointer, although it can be named anything).<br>// this reads the current count from the file.<br>$fp        = fopen( $filename,"r+");<br>// lock the file - this will wait until noone else has a lock<br>flock($fp, LOCK_EX);<br>$Old      = fgets($fp);<br><br>// Split the current data where there is an equal sign<br>$Old = split ("=", $Old, 5);<br><br>// Increment the old count from the file by 1.<br>$NewCount = $Old[1] + 1;<br><br>$New = "Count=$NewCount";<br><br>// time to rewrite the file, so rewind to the beginning<br>fseek($fp, 0, SEEK_SET);<br>fputs($fp, $New);<br>// release the lock<br>flock($fp, LOCK_UN);<br>fclose( $fp );<br><br>// Finally print the new count out so the flash movie can read the number in.<br>print "Count=$NewCount";<br><br>?>


    Musicman

    Metal Fusion

    • Guest
    Re:Php flash counter questions
    « Reply #3 on: 12/21/02, 04:41 »
    ok i got taht
    but heres another problem
    my counter is in a movieclip called counter and counter is in a movieclip top which is placed at root
    how can i specify the php script to point to _root.top.counter?

    Thanks in advance

    Thanks
    metal Fusion

    Musicman

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 2685
      • View Profile
      • Email
    Re:Php flash counter questions
    « Reply #4 on: 12/21/02, 04:56 »
    Hi,

    you dont have to...
    If the flash part uses loadVariables('counter.php', this) it should work in any place in the clip heirarchy

    Musicman

    Metal Fusion

    • Guest
    Re:Php flash counter questions
    « Reply #5 on: 12/21/02, 22:09 »
    hi
    it still doesnt work for me:
    this is what i ahve:
    2 layers in movie clip: Counter
    layver actions:
    frame 1: loadVariablesNum ("PHPCounter.php?ran="+random(9), 0);
    Frame 2: loadVariablesNum ("PHPCounter.txt?ran="+random(9), 0);
    frame 50: gotoAndPlay (2);

    layer textbox:
    dynamic textfiled variable: count

    PHPCounter.php
    <?php

    $filename = "PHPCounter.txt";  // text file to write to (make sure to change permissions).

    // Opens a new file for first reading, then writing to (fp is short for file pointer, although it can be named anything).
    // this reads the current count from the file.
    $fp        = fopen( $filename,"r+");
    // lock the file - this will wait until noone else has a lock
    flock($fp, LOCK_EX);
    $Old      = fgets($fp);

    // Split the current data where there is an equal sign
    $Old = split ("=", $Old, 5);

    // Increment the old count from the file by 1.
    $NewCount = $Old[1] + 1;

    $New = "Count=$NewCount";

    // time to rewrite the file, so rewind to the beginning
    fseek($fp, 0, SEEK_SET);
    fputs($fp, $New);
    // release the lock
    flock($fp, LOCK_UN);
    fclose( $fp );

    // Finally print the new count out so the flash movie can read the number in.
    print "Count=$NewCount";

    ?>

    PHPCounter.txt
    Count=3

    problem:
    the script works
    but it doesnt wshow in the textbox in flash

    Thanks
    Metal Fusion

    Musicman

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 2685
      • View Profile
      • Email
    Re:Php flash counter questions
    « Reply #6 on: 12/22/02, 02:24 »
    Hi,

    get rid of the call to phpcounter.txt (the php returns the information already) and try using "Count"

    Musicman

    Metal Fusion

    • Guest
    Re:Php flash counter questions
    « Reply #7 on: 12/22/02, 06:05 »
    hi musicman
    i tried as you suggested, but the data still wont display.
    But the textfile gets updated correctly.

    Whats wrong???  ???

    Thanks

    MEtal fusion

    Mohsin Sumar

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 1646
    • Mohsin Sumar, Extreme Web Technologies
      • MSN Messenger - mohsinsumar@hotmail.com
      • Yahoo Instant Messenger - mohsinsumar
      • View Profile
      • Extreme Web Technologies
      • Email
    Re:Php flash counter questions
    « Reply #8 on: 12/22/02, 07:26 »
    hmm.. i tried doing this but i donno wat the problem is?

    well.. this is the error that is showed up on the browser wen i chk out my PHPCounter.php file

    Code: [Select]

    Warning: fopen("PHPCounter.txt","r+") - The file access permissions do not allow the specified action. in /host/m/o/h/p/o/r/mohsinsumar.port5.com/counter-tests/PHPCounter.php on line 7

    Warning: Supplied argument is not a valid File-Handle resource in /host/m/o/h/p/o/r/mohsinsumar.port5.com/counter-tests/PHPCounter.php on line 9

    Warning: Wrong parameter count for fgets() in /host/m/o/h/p/o/r/mohsinsumar.port5.com/counter-tests/PHPCounter.php on line 10

    Warning: Supplied argument is not a valid File-Handle resource in /host/m/o/h/p/o/r/mohsinsumar.port5.com/counter-tests/PHPCounter.php on line 21

    Warning: Supplied argument is not a valid File-Handle resource in /host/m/o/h/p/o/r/mohsinsumar.port5.com/counter-tests/PHPCounter.php on line 22

    Warning: Supplied argument is not a valid File-Handle resource in /host/m/o/h/p/o/r/mohsinsumar.port5.com/counter-tests/PHPCounter.php on line 24

    Warning: Supplied argument is not a valid File-Handle resource in /host/m/o/h/p/o/r/mohsinsumar.port5.com/counter-tests/PHPCounter.php on line 25
    Count=1


    and the PHP code is :

    Code: [Select]

    <?php<br><br>$filename "PHPCounter.txt";  // text file to write to (make sure to change permissions).<br><br>// Opens a new file for first reading, then writing to (fp is short for file pointer, although it can be named anything).<br>// this reads the current count from the file.<br>$fp        = fopen( $filename,"r+");<br>// lock the file - this will wait until noone else has a lock<br>flock($fp, LOCK_EX);<br>$Old      = fgets($fp);<br><br>// Split the current data where there is an equal sign<br>$Old = split ("=", $Old, 5);<br><br>// Increment the old count from the file by 1.<br>$NewCount = $Old[1] + 1;<br><br>$New = "Count=$NewCount";<br><br>// time to rewrite the file, so rewind to the beginning<br>fseek($fp, 0, SEEK_SET);<br>fputs($fp, $New);<br>// release the lock<br>flock($fp, LOCK_UN);<br>fclose( $fp );<br><br>// Finally print the new count out so the flash movie can read the number in.<br>print "Count=$NewCount";<br><br>?>


    well.. the probelm ? I donno.. Musicman .. i guess u shud know coz u made the script
    - Best Regards, Mohsin Sumar
    - Mohsin Sumar dot com is hosted by Extreme Web Technologies

    Metal Fusion

    • Guest
    Re:Php flash counter questions
    « Reply #9 on: 12/22/02, 07:28 »
    hey mohsin
    did you get the text to display in your textbox in flash?
    if so how did you do that?

    Thanks
    Metal Fusion

    Mohsin Sumar

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 1646
    • Mohsin Sumar, Extreme Web Technologies
      • MSN Messenger - mohsinsumar@hotmail.com
      • Yahoo Instant Messenger - mohsinsumar
      • View Profile
      • Extreme Web Technologies
      • Email
    Re:Php flash counter questions
    « Reply #10 on: 12/22/02, 07:29 »
    got hte problem.. i chmoded the file to 777 but now the error showed up is:


    Warning: illegal value for second argument in /host/m/o/h/p/o/r/mohsinsumar.port5.com/counter-tests/PHPCounter.php on line 9

    Warning: Wrong parameter count for fgets() in /host/m/o/h/p/o/r/mohsinsumar.port5.com/counter-tests/PHPCounter.php on line 10

    Warning: illegal value for second argument in /host/m/o/h/p/o/r/mohsinsumar.port5.com/counter-tests/PHPCounter.php on line 24
    Count=1


    wat does that mean? n how do I fix it?
    - Best Regards, Mohsin Sumar
    - Mohsin Sumar dot com is hosted by Extreme Web Technologies

    Mohsin Sumar

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 1646
    • Mohsin Sumar, Extreme Web Technologies
      • MSN Messenger - mohsinsumar@hotmail.com
      • Yahoo Instant Messenger - mohsinsumar
      • View Profile
      • Extreme Web Technologies
      • Email
    Re:Php flash counter questions
    « Reply #11 on: 12/22/02, 07:36 »
    well... the text displayed is 1 althe time

    that means that the file is nt written.. those errors pop up

    well.. its easy.. as the PHPCounter.txt has a variable called Count=(number) and the textbox has the variable Count and on Frame2 the action is loading the text file than the text is displayed :D

    if u cant get it to show.. chk the text file for the Variable.. if its Count then chk the fla file to c if the variable of the text file is count too? got it
    - Best Regards, Mohsin Sumar
    - Mohsin Sumar dot com is hosted by Extreme Web Technologies

    Metal Fusion

    • Guest
    Re:Php flash counter questions
    « Reply #12 on: 12/22/02, 08:16 »
    hi mohsin
    i checked my variable for teh dynamic text field and its Counter and the textfiled is also Counter

    I found out the problem
    because php cant send teh data to my flash movie.
    reason is that my visitor counter is in a movie clip (counter) which is in the movie clip (Topconver) which is in the top most layer of teh movie.

    Now how can i tell the script to redirect the result there?


    Thanks
    Metal Fusion

    Mohsin Sumar

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 1646
    • Mohsin Sumar, Extreme Web Technologies
      • MSN Messenger - mohsinsumar@hotmail.com
      • Yahoo Instant Messenger - mohsinsumar
      • View Profile
      • Extreme Web Technologies
      • Email
    Re:Php flash counter questions
    « Reply #13 on: 12/22/02, 09:22 »
    ok.. i guess try this.. it shud work:

    on the location .. most probably the second last line .. this one:

    Code: [Select]
    print "Count=$NewCount";

    change this to:

    Code: [Select]
    print "_root.level1.level2.Count=$NewCount";

    where by level1 is topconver and level2 is counter

    change the level1 and level2 to their respective names as in ur movie..


    hoping that this works :D
    - Best Regards, Mohsin Sumar
    - Mohsin Sumar dot com is hosted by Extreme Web Technologies

    Metal Fusion

    • Guest
    Re:Php flash counter questions
    « Reply #14 on: 12/23/02, 20:23 »
    hm
    didnt work for me

    any ideas?

    Thansk
    Metal Fusion