简体   繁体   中英

Struggling with _POST URLVariable to PHP from AS3

I've been passed an existing Flash project which _POST's data to a URL in it's script. I've tried added more data to the URLVariable, however it doesn't work:

AS3:

        public function SendChatMessageDB(ChatFrom:int)
    {
        var request:URLRequest = new URLRequest("http://www.somewebsite.co.uk/clientUpdateUserInfo.php");           
        var data:URLVariables = new URLVariables();
        data.a = "upChat"; // Existing part of project - Working
        data.sk = "hash"; // Existing part of project - Working
        data.Dat = global.MyFacebookID; // Existing part of project - Working
        data.chat = "screw"; // Added data - Not working!

        request.data = data;
        request.method = URLRequestMethod.POST;                     
        var loader:DataLoader = new DataLoader(request, {name:"userInfo"});
        loader.load();
    }
}

PHP:

<?php

session_start();

        $a = $_POST["a"];
        $sk = $_POST["sk"];

    $xmlData = $_POST["Dat"];

    $security_result = SecurityCheck($sk);

                if( isset($_POST['chat']) )
                {
                    $chatMessage = $_POST("chat"); // Script's functions only work when I comment this out..

The methods only work when I have what's inside the if statement commented out. Can anyone see where I'm going wrong?

Many Thanks, Nigel Clark

If you take a look on the definition of $_POST in the php documentation, you will understand that $_POST is just an array , to see that you can test this code :

<?php

    echo gettype($_POST);        // gives : array

    var_dump($_POST);            // gives : 
                                //  array (size=0)
                                //  empty

    print_r($_POST);             // gives : Array ( ) 

?>

And when you try this code :

<?php

    echo $_POST('key');     // throws this error : PHP Fatal error:  Function name must be a string

?>

You will get a php fatal error because in php, function name can not start with $ as it's variables ( as $_POST ).

So to get the value corresponding to the index key from the $_POST array, we use $_POST['key'] .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM