10 Replies Latest reply on May 13, 2010 3:19 PM by amige

    Deploying AMFPHP & connecting with AIR

    vividmac87

      Hello,

       

      This is my first time deploying amfphp on a live server and I am having problems connecting to it with an AIR application. Here is my code and the error that I am receiving:

       

      MXML:

      <mx:RemoteObject id="amflogin" source="Login" destination="Login" endpoint="http://domain.com/app/amfphp/gateway.php" showBusyCursor="true">
          <mx:method name="validateLogin" result="loginHandler(event)" fault="mx.controls.Alert.show(event.fault.faultDetail.toString(), 'Alert', Alert.OK, this)" />
      </mx:RemoteObject>

       

      Login.php (http://domain.com/app/amfphp/services/Login.php)

      <?php

       

      class Login {
           public function __construct() {
                mysql_connect("localhost","user","password");    
                mysql_select_db("database");
           }
          
           public function validateLogin() {
                   // receives some variables and returns true or false
           }
      }

       

      Error when connecting to http://domain.com/app/amfphp/browser/index.html

      (mx.rpc::Fault)#0
        errorID = 0
        faultCode = "Client.Error.MessageSend"
        faultDetail = "Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Failed"
        faultString = "Send failed"
        message = "faultCode:Client.Error.MessageSend faultString:'Send failed' faultDetail:'Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Failed'"
        name = "Error"
        rootCause = (Object)#1
          code = "NetConnection.Call.Failed"
          description = "HTTP: Failed"
          details = "http://domain.com/app/amfphp/gateway.php"
          level = "error"

       

       

      crossdomain.xml - located at web root - http://domain.com/

      <cross-domain-policy>
      <allow-access-from domain="domain.com" secure="false"/>
      <allow-access-from domain="www.domain.com" secure="false"/>
      <allow-access-from domain="domain.com" to-ports="80,443"/>
      <allow-http-request-headers-from domain="domain.com" headers="*"/>
      </cross-domain-policy>

       

      I have been researching for quite some time, but cannot seem to find what I am doing wrong here. Any help would be greatly appreciated!

       

      Thanks,

      Brian

        • 1. Re: Deploying AMFPHP & connecting with AIR
          vividmac87 Level 1

          Some additional information:

           

          PRODUCTION SERVER
          PHP: 5.2.12
          MySQL: 5.0.89-community
          Operating System: Linux
          Apache: 2.2.14

           

          For amfphp I am using:
          AMFPHP: 1.9

          • 2. Re: Deploying AMFPHP & connecting with AIR
            AdrianWiecek

            Hi,

             

            You say that validateLogin receives some variables, in code you've pasted this function takes no arguments. I think there's something wrong at AIR side because of Client.Error. How do you invoke remote objects method?

             

            Regards,

            Adrian

            • 3. Re: Deploying AMFPHP & connecting with AIR
              vividmac87 Level 1

              Hello Adrian, thanks for the reply. I am invoking my remoteobject method inside of a function that responds to the login_btn click event. Sorry for the confusion about the code. Below is a simplified version of my MXML and PHP.

               

              MXML

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Window xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="450" height="200" resizable="false" maximizable="false">


              <mx:RemoteObject id="amflogin" source="Login" destination="Login" endpoint="http://domain.com/app/amfphp/gateway.php" showBusyCursor="true">
                  <mx:method name="validateLogin" result="loginHandler(event)" fault="mx.controls.Alert.show(event.fault.faultDetail.toString(), 'Alert', Alert.OK, this)" />
              </mx:RemoteObject>


              <mx:Script>
                  <![CDATA[

               

               

               

              /* ////////////////////////////////// CALLS THE PHP FUNCTION THAT VALIDATES LOGIN ////////////////////////////////// */
              private function login_validate():void {
                   amflogin.validateLogin(username_input.text, password_input.text);
              }

               

              /* ////////////////////////////////// HANDLES RESULT OF PHP FUNCTION validateLogin ////////////////////////////////// */
              private function loginHandler(e:ResultEvent):void {           
                  if(e.result == false) {
                      nativeWindow.close();       
                  }else {
                      Alert.show("Not a valid username/password", 'Alert', Alert.OK, this);
                  }
              }


                  ]]>
              </mx:Script>
                      <mx:Form width="100%" height="100%" id="login_form" defaultButton="{login_btn}">
                          <mx:FormHeading label="Login"/>
                          <mx:FormItem label="Username:">
                              <mx:TextInput id="username_input" maxChars="30"/>
                          </mx:FormItem>
                          <mx:FormItem label="Password:">
                              <mx:TextInput id="password_input" maxChars="20" displayAsPassword="true"/>
                          </mx:FormItem>
                          <mx:FormItem>
                              <mx:Button label="Login" id="login_btn" click="login_validate()" />
                          </mx:FormItem>
                      </mx:Form>
              </mx:Window>

               

               

               

              Login.php

              <?php

               

              class Login {
                  public function __construct() {
                      mysql_connect("localhost","user","pw");   
                      mysql_select_db("database");
                  }
                 
                  public function validateLogin($userInput=NULL, $pwInput=NULL) {
                      $user = mysql_real_escape_string($userInput);
                      $pw = mysql_real_escape_string($pwInput);
                     
                      $querystring = "SELECT users_id, users_username, users_password FROM tbl_users WHERE users_username = '".$user."' AND users_password = '".$pw."'";
                      $query = mysql_query($querystring);
                      $numrows = mysql_num_rows($query);
                      if ($numrows == 1) {
                          return true;
                      }else {
                          return false;
                      }
                  }
                 
              }

               

              I know that there will be errors in this simplified version that I constructed, but it demonstrates the way that I am calling my remoteobject method. I got all of my code to work locally, but I am having a problem getting this project to work on a production server.

               

              Thanks again,

              Brian

              • 4. Re: Deploying AMFPHP & connecting with AIR
                AdrianWiecek Level 3

                Hi again,

                 

                If this problem appears only on production server, there can be some configuration issues on that server.

                Maybe this link will help you:

                 

                http://wadearnold.com/blog/flash/amfphp/apache-mod_security-oddity-in-amfphp

                 

                Try to use a web debugger like Fiddler or Charles or any other tool to let you look at the response code from server.

                 

                Regards,

                Adrian

                • 5. Re: Deploying AMFPHP & connecting with AIR
                  vividmac87 Level 1

                  Hey Adrian,

                   

                  I agree, I also think that the problem has to do with some configuration issues on the server, I just don't know what it could be. I came across that post by Wade Arnold as well, but I checked phpinfo and I could not find mod_security. However, I still attempted to place a .htaccess in the amfphp/gateway.php directory with the following content:

                   

                  <ifmodule>SecFilterInheritance Off</ifmodule>

                   

                  This did nothing and the problem still persists.

                   

                  I attempted using Charles, but a lot of the response means nothing to me. Here is a summary of what was returned from Charles.

                   

                  <?xml version="1.0" encoding="UTF-8"?><charles-session>
                  <transaction>
                  <request status="Complete" method="POST" protocolVersion="HTTP/1.1" protocol="http" host="domain.com" actualPort="80" path="/app/amfphp/gateway.php" clientAddress="/127.0.0.1" startTime="2010-03-23T18:40:17.567-04:00" startTimeMillis="1269384017567" requestTime="2010-03-23T18:40:17.657-04:00" requestTimeMillis="1269384017657" responseTime="2010-03-23T18:40:17.719-04:00" responseTimeMillis="1269384017719" endTime="2010-03-23T18:40:17.720-04:00" endTimeMillis="1269384017720">
                  <body headers="377" body="244" mime-type="application/x-amf">
                  <![CDATA[AAMAAAABAARudWxsAAIvMQAAAOAKAAAAAREKgRNNZmxleC5tZXNzYWdpbmcubWVzc2FnZXMuQ29t
                  bWFuZE1lc3NhZ2UTb3BlcmF0aW9uG2NvcnJlbGF0aW9uSWQVdGltZVRvTGl2ZRN0aW1lc3RhbXAX
                  ZGVzdGluYXRpb24PaGVhZGVycxNtZXNzYWdlSWQJYm9keRFjbGllbnRJZAQFBgEEAAQABgEKCwEl
                  RFNNZXNzYWdpbmdWZXJzaW9uBAEJRFNJZAYHbmlsAQZJQTEyQzg5QTUtRDcyQi01QjM3LTVDREQt
                  OEQyRUY2NzVBNjdBCgUBAQ==]]></body></request>
                  <response status="500" headers="176" body="668" mime-type="text/html" charset="iso-8859-1">
                  <body><![CDATA[<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
                  <html><head>
                  <title>500 Internal Server Error</title>
                  </head><body>
                  <h1>Internal Server Error</h1>
                  <p>The server encountered an internal error or
                  misconfiguration and was unable to complete
                  your request.</p>
                  <p>Please contact the server administrator,
                  webmaster@domain.com and inform them of the time the error occurred,
                  and anything you might have done that may have
                  caused the error.</p>
                  <p>More information about this error may be available
                  in the server error log.</p>
                  <p>Additionally, a 404 Not Found
                  error was encountered while trying to use an ErrorDocument to handle the request.</p>
                  </body></html>
                  ]]></body></response></transaction></charles-session>

                   

                   

                  Could this possibly not be working because I'm not sending any headers when I call my method?

                   

                  - Brian

                  • 6. Re: Deploying AMFPHP & connecting with AIR
                    vividmac87 Level 1

                    Well, turns out that I had a permission problem with my files. The server that is hosting my files does not allow for 0777 permission on a shared server. Glad that I figured it out. Thanks for the help Adrian.

                    • 7. Re: Deploying AMFPHP & connecting with AIR
                      dopbizdev

                      What folder had 777 permissions? I am finding that this is only happening with PHP 5.2.12. It works fine on 5.2.11. I am not so sure the folder permissions is the correct solution.

                      • 8. Re: Deploying AMFPHP & connecting with AIR
                        amige

                        Hello    

                         

                        I had the same problem that vividmac87, i got crazy looking for the solution, please tell me how did you solve this??

                        • 9. Re: Deploying AMFPHP & connecting with AIR
                          vividmac87 Level 1

                          Hello amige,

                           

                          All of my folders are set to 0755 permissions and all of my files are set to 0644. Check to see if the files and folders in your amfphp structure match these permission settings. Hope this helps.

                           

                          Brian

                           

                          --

                          http://www.brianmclachlin.com

                          • 10. Re: Deploying AMFPHP & connecting with AIR
                            amige Level 1

                            Thanks for the answer

                             

                            Unfortunately I have the folders and files correctly, did you change something on the server?? As the mod_security or create a .htaccess file??

                             

                            TIA