flash data integration:
I'm reading David Powers' book on Flash and PHP5. So far I feel like it's been
very helpful but there are apparently a few things I am not getting my head
around.
Trying to modify a sessions login script using AS2.0, PHP5 and mySQL5. My
problem is that I'm getting an undefined session variable back from the PHP
script. Can someone give me some guidance as to how and where I'd place
something in PHP to test (via trace?) if things are getting done? If I manually
place the login variables (username and pw), and test the PHP script in a
browser, it's fine. It's just with Flash that I'm having problems.
//IN FLASH//
function checkDetails():Void {
// this gathers the form input and sends it to the PHP script and clear any
error messages
error_txt.text = "";
loginDets.username = userName_txt.text;
loginDets.pwd = pwd_txt.text;
loginDets.sendAndLoad("http://localhost/~Amy/phpflash/tagPhoneList/processLogin
..php?ck="+new Date().getTime(), loginResponse);
}
function doLogin():Void {
trace(this.test);
if (this.authenticated == "ok") {
trace("authenticated");
// if login details OK, load protected page
getURL("http://localhost/~Amy/phpflash/tagPhoneList/registerManagement.php");
} else {
// otherwise display error message
error_txt.text = "Sorry, access denied.";
}
}
// assign event handler to login button
submit_btn.onRelease = checkDetails;
// create LoadVars instances to send and receive data
var loginDets:LoadVars = new LoadVars();
var loginResponse:LoadVars = new LoadVars();
loginResponse.onLoad = doLogin;
// set color for text input field borders
userName_txt.borderColor = 0x7C756C;
userName_txt.tabEnabled = true;
userName_txt.tabIndex = 1;
pwd_txt.borderColor = 0x7C756C;
pwd_txt.password = true;
pwd_txt.tabEnabled = true;
pwd_txt.tabIndex = 2;
Selection.setFocus("userName_txt");
// initialize error message text area
this.createTextField("error_txt", this.getNextHighestDepth(), 50, 60, 400, 25);
// set the text format for the error message area and apply it
var errorFormat:TextFormat = new TextFormat();
errorFormat.bold = true;
errorFormat.color = 0x7C756C;
errorFormat.font = "Arial,Helvetica,_sans";
errorFormat.size = 18;
errorFormat.align = "center";
error_txt.setNewTextFormat(errorFormat);
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
if (Key.isDown(Key.ENTER)) {
checkDetails();
//trace("enter pressed");
}
};
Key.addListener(keyListener);
stop();
//
//IN PHP//
<?php
// check correct variables have been received through the POST array
if (isset($_POST['username']) && isset($_POST['pwd'])) {
// initiate the session
session_start();
// include the Database classes
require_once('../classes/database_mysqli.php');
// escape quotes and apostrophes if magic_quotes_gpc off
foreach($_POST as $key=>$value) {
if (!get_magic_quotes_gpc()) {
$temp = addslashes($value);
$_POST[$key] = $temp;
}
}
// create a Database instance and check username and password
$db = new Database('localhost','myUN','mypassword','myDB');
$sql = 'SELECT * FROM users WHERE userName = "'.$_POST['username'].'"
AND password = "'.sha1($_POST['pwd']).'"';
$result = $db->query($sql);
// if a match is found, approve entry; otherwise reject
if ($result->num_rows > 0) {
$_SESSION['authenticated'] = $_POST['username'];
echo 'authenticated=ok';
}
else {
echo 'authenticated=getLost';
}
// close the database connection
$db->close();
}
?>
//
//mySQL has 3 columns... primaryKey, userName and password//