Skip to main content
September 4, 2011
Answered

Password authentification for as3 php upload

  • September 4, 2011
  • 1 reply
  • 2120 views

Hi

I'm making an Air file that uploads and overwrites an XML file.

So far, the php is very simple:

$everything = $_POST['saveThisXML'];

  $everything = stripslashes($everything);
   $toSave = $everything; 

   $fp = fopen("settings.xml", "w");
   if(fwrite($fp, $toSave)) echo "writing=Ok";
   else echo "writing=Error";
   fclose($fp);

I'd like to set up a user name and passowrd that the user enters in the Air app.  Is it then just a matter of sending POST data to the php file, and have it check the user and pass variables?  Is that a reasonably safe way to do it?  If not, can someone please point me in th edirection of a good tutorial that they're used on this topic?

Thanks again guys.

Shaun

This topic has been closed for replies.
Correct answer kglad

I'd like to set up a user name and passowrd that the user enters in the Air app.  Is it then just a matter of sending POST data to the php file, and have it check the user and pass variables?

yes, that's good.


Is that a reasonably safe way to do it?

it's not safe if the passwords are in the php file but it's safe if the php file retrieves the data from a secured database.

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
September 4, 2011

I'd like to set up a user name and passowrd that the user enters in the Air app.  Is it then just a matter of sending POST data to the php file, and have it check the user and pass variables?

yes, that's good.


Is that a reasonably safe way to do it?

it's not safe if the passwords are in the php file but it's safe if the php file retrieves the data from a secured database.
September 4, 2011

OK

So somewhere along the line, the user is going to have to set up a database.  I can use PHP to do that though, right?  And they'd just have to run the php page once to set it up.

Thanks kglad.

Also, I can successfully upload data from a string (myString) in Flash using PHP:

var myData:URLRequest = new URLRequest("http://www.blah.com/saver.php");
        myData.method = URLRequestMethod.POST;
        var variables:URLVariables = new URLVariables();
        var origEverything:String = myString;
        variables.saveThisXML = origEverything;       
                   
        myData.data = variables;
        var loadData:URLLoader = new URLLoader();
        loadData.dataFormat = URLLoaderDataFormat.VARIABLES;
        loadData.addEventListener(Event.COMPLETE, doneBaby);
        loadData.addEventListener(IOErrorEvent.IO_ERROR, dataLoadError);
        loadData.load(myData);  

However, when I try to add two variables to send to php, I get a named pairs error.  Here's what I tried adding (in bold):

var myData:URLRequest = new URLRequest("http://www.blah.com/saver.php");
         myData.method = URLRequestMethod.POST;
         var variables:URLVariables = new URLVariables();
         var origEverything:String = myString;

          var passTest:String = 'testPW';
         variables.saveThisXML = origEverything;     

     variables.saveThisPass = passTest;     

        myData.data = variables;
         var loadData:URLLoader = new URLLoader();
         loadData.dataFormat = URLLoaderDataFormat.VARIABLES;
         loadData.addEventListener(Event.COMPLETE, doneBaby);
         loadData.addEventListener(IOErrorEvent.IO_ERROR, dataLoadError);
         loadData.load(myData);  

Why would that generate an error?

Cheers kglad

Shaun

kglad
Community Expert
Community Expert
September 4, 2011

your dataFormat property is incorrect.  leave it unchanged, if that was working before.

(and, you wouldn't normally setup a database using php.  that would be pretty laborious.  every server i've worked on has a user interface that executes the php for you.  myphpadmin is the most common, by far.)