0

I'm trying to use urlLoader but it's not working and I don't know why..

I've created a php file that I have uploaded. Here's the php code :

<?php

    $psPreRegEmail=$_POST['sEml'];
    $FRM_ID=$_POST['sID'];
    $psBD=$_POST['sBD'];     

    echo "email=".$psPreRegEmail;
    echo "&id=".$FRM_ID;
    echo "&db=".$psBD;

?>

Here is my AS3 code :

var request:URLRequest = new URLRequest('http://www.mysite.fr/login.php')
var variables:URLVariables = new URLVariables()
    variables.sEml = 'steph4'
    variables.sID = 'steph5'
    variables.sBD = 'steph6'

request.data = variables
request.method = URLRequestMethod.POST
var loader:URLLoader = new URLLoader();
    loader.addEventListener(Event.COMPLETE, handleComplete);
    loader.load(request)

function handleComplete(event:Event) {

    var loader:URLLoader = URLLoader(event.target)
    var vars:URLVariables = new URLVariables(loader.data)

    trace('vars.email: '+vars.email)
    trace('vars.id: '+vars.id)
    trace('vars.db: '+vars.db)

} 

No errors, but when I'm going at http://www.mysite.fr/login.php it displays : email=&id=&db=

Why don't I see : ???

email=steph4
id=steph5
db=steph6

I'm starting to wonder if it's possible to send data from an AIR app to a php file on a server ?? Maybe it's because, for security measure, it's impossible to send data to an URL ?

akmozo
  • 9,829
  • 3
  • 28
  • 44
user3094896
  • 195
  • 1
  • 8

2 Answers2

0

I'm a complete noob with php, buts its obvious that you're not writing any data. Your flash file is tracing the 'echos' from the php, but your php is not retaining any data that would show up when you simply call it via html.

So try having your php write your variables to a text file, like this:

<?php
$psPreRegEmail=$_POST['sEml'];
$FRM_ID=$_POST['sID'];
$psBD=$_POST['sBD'];

$myFile = "testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $psPreRegEmail;
fwrite($fh, $stringData);
$stringData = $FRM_ID;
fwrite($fh, $stringData);
$stringData = $psBD;
fwrite($fh, $stringData);
fclose($fh);

echo "eemail=".$psPreRegEmail;
echo "&id=".$FRM_ID;
echo "&db=".$psBD;

?>

Now you can read-out your file like this:

http://www.mysite.fr/testFile.txt

or write some php code to read it for you.

Craig
  • 814
  • 1
  • 6
  • 9
0

Your AS3 code is fine, but in your PHP code you should do like this :

<?php

    $psPreRegEmail = $_POST['sEml'];
    $FRM_ID = $_POST['sID'];
    $psBD = $_POST['sBD'];

    echo "email=".$psPreRegEmail."&id=".$FRM_ID."&db=".$psBD;

?>

About your question, why you don't get what you want when you open http://www.mysite.fr/login.php ? This is because your $_POST array is empty and then your vars are empty. You should just run your project and you will get this :

vars.email: steph4
vars.id: steph5
vars.db: steph6
akmozo
  • 9,829
  • 3
  • 28
  • 44