Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write to a text file from Flash using Perl/PHP? 1

Status
Not open for further replies.

TulsaJeff

Programmer
Jan 29, 2001
870
US
I have a client who has approximately 8 users, each with their own page/frame in the Flash website. He simply updates online text files and it is pulled in for the user to sign in and see their info dynamically.

Now he asks me if it is possible for him to know if a user has read/signed in to his page.

I am wondering how hard it would be to write a simple variable to a text file which Flash could then pull into his page beside that users name stating "yes" or "no"?

I have a flash counter which writes a number+1 to a text file everytime someone comes to the site... looks like it would work somehow along the same lines.

Any help is greatly appreciated. Ya' Gotta Love It!
sleepyangelsBW.jpg
 
As far as flash goes: I'm ignorant. Never developed with it, haven't the slightest idea as to it's capabilities.

But in response to the question: how hard it would be to write a simple variable to a text file?

Not hard at all. I don't know how your client's users log in to their sites, but when they log in, a simple script could write to a text file the user name and the time. That (from what I read) would suffice.

Sorry if this isn't much help.

--Jim
 
I also am totally ignorant with Flash. However, if flash can make a HTTP call back to your web server, you could put a piece of CGI on the server that just responds to that call. If Flash is intelligent enough to pass the user id with the HTTP request
Code:
([URL unfurl="true"]http://www.server.com/cgi-bin/log_this.cgi?user=someUser)[/URL]
, then the cgi code would just parse out the user id, get the current time and write both to a log file.

The cgi might look something like....
(this has not been run and may need a syntax tweak)..

Code:
#!/usr/local/bin/perl -T
use CGI;
use strict;
my $cgi = new CGI;
my $user = param('user');

# confirm that the user id submitted is one of your users
# If not, it may be some one trying to highjack your cgi 
# for deleterious purposes.
unless ($user =~ /^user1|user2|user3|....|user8$/) { die; }

open(LOGFILE,">>some_path_file") or die; 
# Just die.  Don't need to send error back to client.
my $time = localtime;
print LOGFILE "$time|$user\n";
close LOGFILE;

You may notice that this does not return anything to the Flash HTTP request (if a Flash HTTP request is possible). It just catches the user id and writes it to disk. So, if Flash requires a response, this code would need to be fleshed out a little. Also, if this approach will work, you will want to use some file locking (flock) to maintain your log file appropriately.

'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top