PDA

View Full Version : get data from cgi


jerome_lab
02-08-2001, 07:54 PM
I've written a small cgi that gets the visitor IP number and returns a html page. I want to do the same but with flash, is it possible for a textfield to get external data from a cgi and in this cas how do I have to format the output for flash to understand it?

Here's the cgi (perl):

#!/usr/bin/perl

if (!$END{'REMOTE_HOST'}) {
$host=$ENV{'REMOTE_ADDR'};
}
else {
$host=$ENV{'REMOTE_HOST'};
}

#here it outputs html

print "Content-type: text/html\n\n";
print "<BODY BGCOLOR=#FFFFFF text=#FFFFFF>";
print $host;

#end of script

Jesse
02-09-2001, 12:19 AM
Flash can interact well with CGI and PHP but I haven't ever seen it get a return() from a script. The way I surpass this problem is to call my PHP and have it output a temporary text file (same file every time, so it just overwrites it). My data is written into that text file on the server. In your case, the form would be:

IP=123.123.123.123

And then I use LoadVariablesNUM() to load up the text file (but after a few seconds to give my script time to run...)

If anyone knows how to get flash to recieve a return() type data string, I'd be most interested.

Cheers

Jesse

jerome_lab
02-09-2001, 08:42 AM
Thanks, seems to be a solution but as always I have more questions than before...

Is it possible to get the ip number from a php script, in this case it could be a good reason to switch from perl to php...Yet another language to learn. In general, is it any good reasons to choose php over perl or another language to interact with flash? As I'm new to flash, this maybe is a naive question, I only know javascript and so the migration to actionscript was easy, I've found some open-source projects as Perl::Flash, but these projects are still under heavy development , is there similar projects with php and is the development of such applications more advanced in php? If anyone has an opinion to these issues, please let me know.
link to Perl::Flash >>
http://www.2shortplanks.com/Flash/index.html

Jesse
02-09-2001, 09:55 AM
PHP is just my language of preference for server side scripting. I only started learning a while ago because I was interested in making dynamic pages and I wasn't too impressed with ASP. Since then I've gotten into mySQL/PHP combo sites (my new one will come up in about a week).

You can retrieve the users IP with PHP but it depends on what server program your host is running. For Apache Webserver (which is coverred inthe PHP Manual), you just do the following:

<?php
echo $REMOTE_ADDR;
?>

That will print out the IP of the user to the page. $REMOTE_ADDR is the Apache variable which holds this info, but like I say, if your server isn't running Apache chances are it wouln't work.

If you've got your CGI doing what you want, stick with it I say. I just find PHP easier to learn and it has some groovy new included functions since it's a language still in development.

Cheers

Jesse

jerome_lab
02-09-2001, 11:39 PM
To anyone interested in the perl script writing a text file with the IP number, here it is:

#!/usr/bin/perl
if (!$END{'REMOTE_HOST'}) { #getting the IP
$host=$ENV{'REMOTE_ADDR'};
}
else {
$host=$ENV{'REMOTE_HOST'};
}
#open the file writing ipnumber=123.123.123.123
if (open(LOGFILE, ">ipnumber.txt")) {
print LOGFILE ("ipnumber=");
print LOGFILE ( $host );
close(LOGFILE);
}
#end of script

Works on apache and some other Linux/unix servers

howhiareu
05-07-2001, 09:28 PM
I have found that you don't have to output a textfile.txt with your return variables.

A basic GetMyVars.asp script looks like this:

<%
ASPVar1="Some+Value+I+Want"
ASPVar2="Another+Value+I+Want"

Response.Write("FlashVar1=" & ASPVar1)
Response.Write("&FlashVar2=" & ASPVar2)
%>

with no other html code, Flash treats the asp as if it were a plain old textfile.txt. No GET or POST required! Easier answer than I was looking for. Why mess with Textstream objects when you don't have to?

The Flash action looks like this:

on (release) {
loadVariablesNum ("/GetMyVars.asp", 0);
}

Here is the above in action:
http://www.digits-dev.com/SimpleASPShow.html

Jesse
05-08-2001, 07:57 AM
Yes we discoverred this too, there is a tutorial about it in the Intermediate section.

Cheers

Jesse

Chilton
05-22-2001, 09:21 PM
And the same script in Valiant (due out next week!):

userIP = *ClientIPAddress*
append file "ipnumber.txt" with userIP

respond FLASH userIP

html

gooky
06-05-2001, 12:11 AM
You could also do it by using the XML object. I do not now how, but u can do it. Use XML.sendAndLoad

DonCapo
06-28-2001, 03:46 PM
Hi,

How can i make Flash to retrieve a value returned by a Javascript funtion ?

Let's say (exemple) i have a Javascript defined in my web page and called Returnmypoints() that returns, let's say an integer number.

Can i call this function from a Flash movie AND import at the same time the returned value, store it in a variable and display it in my flash movie ?

Anyone deal with this ? Tutorials, exemples would be appreciated.

Thank you.

Manuel

gooky
06-28-2001, 05:14 PM
yes you can do that... You should take a look at FScommand(javascriptcommand, arguments) in the Flash5 manual. This one executes a javascript function, lets call this function "PassFlash_DOfscommand"(javascriptcommand=PassFlash). The function "PassFlash_DOfscommand" can then give back the answer to the flash movie, see this URL on how to do this:
http://www.macromedia.com/support/flash/ts/documents/set_variables.htm#javascript

This document contains an error...(missing something). You should ALSO put a id=movie(if the movies filename is movie.swf) in the OBJECT tag if it is not alreadt there!

That is it... hope you will have fun with this - I have! If you have any problems, contact me at email: [email protected] , and then I can send you a tutorial

Originally posted by DonCapo
Hi,

How can i make Flash to retrieve a value returned by a Javascript funtion ?

Let's say (exemple) i have a Javascript defined in my web page and called Returnmypoints() that returns, let's say an integer number.

Can i call this function from a Flash movie AND import at the same time the returned value, store it in a variable and display it in my flash movie ?

Anyone deal with this ? Tutorials, exemples would be appreciated.

Thank you.

Manuel