View Full Version : PHP into Flash
mdipi
May 29th, 2003, 08:18 PM
Hey guys. I got a script for a PHP counter but i want to display it in flash. so on the last line of my PHP script i added:
$variable="variable=$variable";
echo $variable
then in flash i am using
counterText=loadVariables("counter.php");
is that how i would go about doing it? I was talking to David and he helped me this far, but we both wanted to doubble check to make sure thats how you would do it.
Any help is appreciated-
-Mike
PS: Here is the counter script:
<?php
$count_my_page = ("hitcounter.txt");
$hits = file($count_my_page);
$hits[0]++;
$fp = fopen($count_my_page , "w");
fputs($fp , "$hits[0]");
fclose($fp);
echo $hits[0];
?>
This is before adding what i said above btw
ahmed
May 29th, 2003, 10:53 PM
if you follow what i posted here it should work :)
http://www.kirupaforum.com/forums/showthread.php?s=&threadid=18524&highlight=counter
mdipi
May 30th, 2003, 02:04 PM
i knew i saw that thread some where/ when i searched it didnt find it. thaks!
mdipi
May 30th, 2003, 02:47 PM
Ahmed: i am using this code in the first frame of my movie:
count=loadVariables("counter.php", 0);
but the thing is that it wont show up in my text box of count. i can provide the FLA if thats what you need, but i am using the code above so i dont htinkits the PHP
ahmed
May 30th, 2003, 04:30 PM
use this actionscript:
myTextbox.variable = myCounter
lv = new LoadVars()
lv.onLoad = function(success) {
if(success) {
myCounter = this.myCounter
}
}
lv.load("counter.php");.. that should load the variable 'myCounter' and display it in the textbox :)
mdipi
May 30th, 2003, 04:36 PM
ok ahmed i will try it, thanks! but just a question, shouldnt loadVariables have worked?
ahmed
May 30th, 2003, 04:39 PM
the way you were trying to do it, it won't :)
this could've worked:
myTextbox.variable = myCounter
loadVariables("counter.php", this)
// when loadVariables is done loading, the variable myCounter in the php script will be
// included in the flash movie, and then loaded into the textbox :)
mdipi
May 30th, 2003, 06:34 PM
ahmed, the first code didnt werk. i will try this one.
mdipi
May 30th, 2003, 06:41 PM
ahmed, unfortuanatly that doesnt work either. i honestly dont know why, i think i am doing everything right...but i just dont know...if you want here is the fla to the project.
www.mdipi.com/php/miniml.fla
ahmed
May 30th, 2003, 07:08 PM
where's your script located?
ahmed
May 30th, 2003, 07:11 PM
ok.. you need to have the field's instance name set as 'myTextbox'.. both methods should work :)
mdipi
May 30th, 2003, 08:19 PM
doh!
lol thanks a ton! lol how stupidof a mistake was it?
mdipi
May 30th, 2003, 08:22 PM
omgosh! still nothing! i odnt get it!
andr.in
May 31st, 2003, 02:21 AM
ok let's see now...
<?
$filename = "TestCounter.txt";
$file = fopen( $filename,"r");
$OldCount = fread($file, 25);
fclose( $file );
$OldCount = split ("=", $OldCount, 25);
$NewCount = $OldCount[1] + '1';
$New = "&count=$NewCount";
$file = fopen( $filename,"w+");
if (flock($file, 2)) {
fwrite($file, $New, 100); }
fclose( $file );
print "&count=$NewCount";
?>
if (flock($file, 2)) { <--- this line blocks the file or something! I saw it in a tute somewhere! Anyway it keeps the count from resetting when a bunch of ppl visit the site at the same time n' all.
Are you doing a Live counter or just a counter?
You can see my live one here: <a href="http://www.vmkdsn.com/sykopage/counter/TestCounter.htm">Syko's Live Counter</a>
<b>NB! Be sure to change the permissions of the txt file to 777</b>
mdipi
May 31st, 2003, 10:08 AM
Well syko its just that i want it too count when ppl visit lol. i am not to sure what you mean by live. though. but i will change the permission right now...(oops)
edit one:
i changed them and still nothing. i will try your code though
edit two:
tryed syko's php and still nothing. i has to be with the flash. my code is in the first frame and is as follows:
myTextbox.variable = myCounter
loadVariables("counter.php", this)
andr.in
May 31st, 2003, 01:10 PM
check my .fla file here: http://www.vmkdsn.com/sykopage/counter/TestCounter.fla
I have the tetbox named the same as the variable in the txt file! I alwasy have a problem with that!
And by Live Counter I meant that the counter refreshes itself all the time so you don't have to refrsh the page to refresh it!
[ go http://www.vmkdsn.com/sykopage/counter/TestCounter.htm, opne up a new window and go to the same URL and see it increase! ] ( it will refresh after a period of time)
mdipi
June 9th, 2003, 08:45 PM
syko, i tore apart some of the code you gave me and got it to display 1, but it never increments...like with this code in your sample fla
loadVariablesNum("TestCounter.txt?cnum="+random(99999), 0);
that loads the text file just fine, but the php is never executed. lol so where do i put the php in all of this?
mdipi
June 9th, 2003, 08:55 PM
i placed the php but still no werk! the fla is attached.
www.mdipi.com/TextCounter.txt
thats the txt file
and the PHP code is exactly as you posted.
andr.in
June 10th, 2003, 12:30 PM
wops! Sry for the delay!
I wish I could view that .fla but my hard-drive is all screwqed up right now.
the varname of the textbox is "count" right?
Your going trough the same thing as I did. At first it didn't show me anything, then it was just "1" and then voila.
Try executing the php directly! ( www.something.sth/yourphp.php ) and see if it gives ya any errors.
And also if you have an action loading the textfile loadvariablesnum("txtfile.txt"); then delete it or put "//" symbols in front of it and see if it still shows the "1" there.
Jubba
June 10th, 2003, 12:55 PM
Not sure if your question is answered or not... but here is a code that I would use for a simple PHP hit counter...
here is a link to the working copy. Hit refresh a couple of times...
http://www.bluefinatlantic.com/egTest/count.php
<?
$file = "count.txt"; //define file
$fp = fopen($file, "a+"); //open file for read and writing
$data = fread($fp, 80000); //read file to retrieve data
ftruncate($fp, 0); //Cuts file length to zero - Erases previous value
$new = $data + 1; //Adds to counter
fwrite($fp, $new); //Writes the new number into the textfile
fclose($fp); //Closes the file
print "count=".$new; //Prints out the variable so Flash can read it.
?>
This only saves a single number to the text file, so there is no need to manipulate strings or anything...
Then your Flash code would be..
loadVariablesNum("http://www.somesite.com/phpFile.php", 0, "POST");
and on your main stage have a textbox that has the variable name of "count" (without the quotes).
if you want a sample file I can make one up...
andr.in
June 11th, 2003, 03:59 AM
Jubba always know the easiest way...
Jubba
June 11th, 2003, 09:22 AM
just because I am lazy :P
mdipi
June 11th, 2003, 05:41 PM
i will try it. thanks guys, this is harder than i thought lol/
mdipi
June 11th, 2003, 06:09 PM
Jubba could i see that example please?
EDIT"
Warning: fopen(count.txt) [function.fopen]: failed to create stream: Permission denied in /home/mdipi/public_html/count.php on line 13
Warning: fread(): supplied argument is not a valid stream resource in /home/mdipi/public_html/count.php on line 15
Warning: ftruncate(): supplied argument is not a valid stream resource in /home/mdipi/public_html/count.php on line 17
Warning: fwrite(): supplied argument is not a valid stream resource in /home/mdipi/public_html/count.php on line 21
Warning: fclose(): supplied argument is not a valid stream resource in /home/mdipi/public_html/count.php on line 23
count=1
thats the error message i get when i try to accsess the php file.
Jubba
June 12th, 2003, 01:23 AM
it means that it can't open the file for reading and writing.
Its not CHMODed to the correct settings. Its needs to be set at 777
mdipi
June 12th, 2003, 04:21 PM
i did...thats when i got the error message. hmm i will doubble check it though
Jubba
June 13th, 2003, 12:50 AM
it wouldn't do that if your file was CHMODed correctly. because its denying your permissions.
can you post all of your code for me?
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.