A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Help me - Flash save to .txt using php

  1. #1
    Working On An Online RPG grimm 88's Avatar
    Join Date
    Sep 2007
    Location
    Nowhere
    Posts
    280

    Help me - Flash save to .txt using php

    hi, i really need help with understanding this, and before i get a load of replys saying 'use the search function' or whatever, let me tell you that i already did... i found a few examples but i am a total noob to php

    so what i need is... somebody who can either tell me step by step instructions on how to write the php and actionscript required for this to work OR an example with comments (preferably someone who can explain it to me though )

    anyway... here is a little more background on what i am trying to achieve:

    i want to have a user creation page where they enter a username and password, the php then loads up the .txt file and writes the new user into it with something like:

    username=harry983
    harry983_password=harrypassword

    then at the login screen, it first checks wether the username that the user has entered is valid and matches with one in the text file, and if it is not found in the text file stop and say 'username invalid' in a text box, if it is found, check to see wether the password they entered matches username_password, if it doesn't match display 'password invalid' in a text box, and if it is correct then it should load other pieces of data like username_age

    anyway... thats basically what i am trying to achieve and i know loads of flash... its just the php and the communication actionscrpit between flash and the php file that is confusing me
    Last edited by grimm 88; 02-05-2008 at 04:49 AM.

  2. #2
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    this is just part of the solution (since it would allow to re-register) but it looks like this
    Code:
    <?
    $username = $_POST['username'];
    $password = $_POST['password'];
    $username = stripslashes($username); // we dont want O'something to become O\'something
    $password = stripslashes($password);
    $fp = fopen("users.txt", "a");
    fputs($fp, "$username\t$password\n");
    fclose($fp);
    ?>
    Note that the resulting file will have one user and pass per line, with a tab character in between. You certainly would not want a file that repeats
    username= for every user.
    On the flash side you would just use a common loadvars.
    Now, for the php to actually work, you need a writable file. On a common linux/unix server, you would just upload an empty file and then chmod it to 666 (in your ftp program, look for properties or permissions - if there is a set of check boxes instead of the numeric entry, check r and w in all 3 groups)
    A comment on the login behaviour: if you have just one message for both wrong user and wrong password, guessing access data takes longer than with separate wrong user and wrong pass messages

    Musicman

  3. #3
    Working On An Online RPG grimm 88's Avatar
    Join Date
    Sep 2007
    Location
    Nowhere
    Posts
    280
    wow, thanks a lot!!! i got it working now, but im using a seperate .txt file for each user since there is a lot more data than just username and password (lots of text files though :S)

    oh dear... i think i broke my method for making a new text file for each user...

    basically i was just copying a file called EXAMPLE.txt and saving it under a new name using php, but now its broken (cause i either deleted something i wasn't suppposed to or edited something somewhere that i shouldn't have edited)

    i was using this to get the new filename: $newname = '$Name.txt'

    but its not working anymore before it was doing it fine, and saving a file called whatever.txt when i entered info into the username box and clicked save... now it either doesn't call the file anything (blank file name containing no info because the other function that writes to it is trying to open user.txt when there is only a file called either $Name or called nothing (my two errors)

    please help me... i think i got php pretty much figured out now, after reading a few tutorials... or at least i can cope with basic flash to php to text commands...

  4. #4
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    how could anybody help you, from just reading your message? Chances are that, by trying your actual url, an error message from php can be seen. Otherwise, one would have to look at the script AND your server.
    Just as a blind guess: could it be that the folder where you put those files does no longer have correct permissions?
    Also, I would like to mention that you should ensure, in your php part, that user names are restricted to valid file name characters (e.g. you would not want to allow / in a name)

    Musicman

  5. #5
    Working On An Online RPG grimm 88's Avatar
    Join Date
    Sep 2007
    Location
    Nowhere
    Posts
    280
    yeh, ok... ill try that now

  6. #6
    Working On An Online RPG grimm 88's Avatar
    Join Date
    Sep 2007
    Location
    Nowhere
    Posts
    280
    yeh, it worked thanks!

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