PHP将“undefined”变量返回到flash

时间:2012-07-19 12:26:02

标签: php flash variables undefined

我不知道什么是错的但是在我登录的那一刻,我希望它显示我登录的hello +用户名。但目前它只显示Helloundefined

这是我的flash代码:

var myurl2:String = "http://localhost:8888/storyboards/check_auth.php";

var scriptLoader2:URLLoader = new URLLoader();
var scriptRequest2:URLRequest = new URLRequest();

scriptRequest2.url = myurl2+"?ck=" + new Date().getTime();

scriptLoader2.addEventListener(Event.COMPLETE, handleLoadSuccess2);
scriptLoader2.addEventListener(IOErrorEvent.IO_ERROR, handleError2);

// turn off right click so that user cannot control the movie
stage.showDefaultContextMenu = false;

scriptRequest2.method = URLRequestMethod.POST;
scriptLoader2.load(scriptRequest2);

function handleLoadSuccess2(evt:Event):void
{

    var variables2:URLVariables = new URLVariables( evt.target.data );

    for (var prop in variables2) {


        trace(prop+" is: "+variables2[prop]);
    }

    if (variables2.authenticated == "y") {
    // if login details OK, load protected page
        nextFrame();

        display_txt.text ="Hello" + variables2.username;
    } else {
    // if login details OK, load protected page
        var url:String = "http://localhost:8888/storyboards/login.html";
        var request2:URLRequest = new URLRequest(url);

        try {
            navigateToURL(request2, '_self'); // second argument is target
            } catch (e:Error) {
            trace("Error occurred!");
            }
}

}

function handleError2(evt:IOErrorEvent):void
{
}

停止();

// ------------------这是我的process_login.php的PHP代码------------------ ---- //

<?php

$host = 'localhost';
$user = 'root';
$password = 'root';


// check correct variables have been received through the POST array
if (isset($_POST['username']) && isset($_POST['pwd'])){


session_start();



// base url
$baseURL = 'http://localhost:8888/storyboards/';


// include info for db connection
//require_once("connection.php");

// escape quotes
if (!get_magic_quotes_gpc()) {
    foreach($_POST as $key => $value) {
        $temp = addslashes($value);
        $_POST[$key] = $temp;
    }
}

// connect to mysql
$connection = mysql_connect($host, $user, $password) ;

if (!$connection) {
    echo '&error=' . mysql_error() . '&';
    die('Could not connect ' . mysql_error());
}

//echo 'Connected successfully.';

// connect to db
$database = 'registerform';

$db = mysql_select_db($database, $connection);

if (!$db) {
    echo '&error=' . mysql_error() . '&';
    die ('Not connected : ' . mysql_error());
}

//echo 'Selected successfully.';

// query
$query = 'SELECT user_name, pwd FROM users WHERE user_name = "' . $_POST['username'] . '" AND pwd = "' . sha1($_POST['pwd']) . '"';

$result = mysql_query($query, $connection);

if (!$result) {
    echo '&error=' . mysql_error() . '&';
    die ('Invalid query: ' . mysql_error());
}



// count the number of records
$numrows = mysql_num_rows($result);

if ($numrows > 0) {


    $_SESSION['authenticated'] = $_POST['username'];

    echo 'authenticated=y' . '&page=' .'pass.php&user_name='.$_SESSION['authenticated'];
} else {
    echo 'authenticated=n&error=' . urlencode('Sorry, access denied.');
}

}


?>


//-----------and my php code for check_auth.php----//

<?php
    // access to the current session
    session_start();

    $_SESSION['username'] = $_POST['username'];

// if session variable authenticated is not set
if (!isset($_SESSION['authenticated'])) {
    echo 'authenticated=n';
} else {
    echo 'authenticated=y';
}
?>

上述代码中是否有任何地方出错了?那个人可以帮助我:(

0 个答案:

没有答案