1

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

这是我的闪存代码:

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';
}
?>

上面的代码中是否有我出错的地方?有人可以帮我吗:(

4

0 回答 0