De ActionScript en PHP
Voeg deze code in het midden van je mxml document toe:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<mx:Script>
<![CDATA[
import flash.events.Event;
import mx.rpc.events.ResultEvent;
import mx.controls.*
private function checkLogin(evt:ResultEvent):void
{
if(evt.result.loginsuccess == "yes")
{
currentState = "Member Area";
}
if(evt.result.loginsuccess == "no")
{
mx.controls.Alert.show("Invalid username/password");
}
}
]]>
</mx:Script>
<![CDATA[
import flash.events.Event;
import mx.rpc.events.ResultEvent;
import mx.controls.*
private function checkLogin(evt:ResultEvent):void
{
if(evt.result.loginsuccess == "yes")
{
currentState = "Member Area";
}
if(evt.result.loginsuccess == "no")
{
mx.controls.Alert.show("Invalid username/password");
}
}
]]>
</mx:Script>
Eerst worden de verschillende classen ingevoegd en daarna word de functie "checkLogin" aangemaakt. De code bij het If-else-statement controleert wat de php pagina heeft teruggegeven. Geeft de php pagina 'yes' dan moet hij zich verplaatsen naar de volgende state namelijk "Member Area". Als er uit de php pagina 'no' komt word er een Alertbox getoond met het bericht dat de gegevens niet goed zijn.
De PHP pagina ziet gewoon als volgt uit:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php require_once('../Connections/connection.php');
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
header("Cache-control: private");
}
$loginUsername = $_POST['username'];
$password = md5($_POST['password']);
mysql_select_db($database_connection, $connection);
$LoginRS__query=sprintf("SELECT name, password FROM tb_login WHERE name=%s AND password=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $connection) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser){
// *** Create the XML.
$output = "<loginsuccess>yes</loginsuccess>";
}else{
$output = "<loginsuccess>no</loginsuccess>";
}
print ($output);
?>
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
header("Cache-control: private");
}
$loginUsername = $_POST['username'];
$password = md5($_POST['password']);
mysql_select_db($database_connection, $connection);
$LoginRS__query=sprintf("SELECT name, password FROM tb_login WHERE name=%s AND password=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $connection) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser){
// *** Create the XML.
$output = "<loginsuccess>yes</loginsuccess>";
}else{
$output = "<loginsuccess>no</loginsuccess>";
}
print ($output);
?>
Natuurlijk moet je sommige dingen in dit script even aanpassen voor eigen gebruik, maar de meeste code moet toch wel te begrijpen zijn. In de laatste regels word de XML gemaakt die terug word gestuurd naar de AIR applicatie.
« vorige pagina | volgende pagina »