Skip to main content
January 31, 2013
Answered

Calling session (user)

  • January 31, 2013
  • 2 replies
  • 1103 views

Hi guys,

I want to display the user name in the dynamic textfield on the login success page (new page) but it keeps giving me 'undefined'. What's the problem?

login.php

<?php

session_start();

$username = $_POST['username'];

$password = $_POST['password'];

$_SESSION['username'] = $username;

. //other codes

.

.

?>

adminPage.php (successpage)

<?php

session_start();

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

$username = $_GET['username'];

    print "session=$username";

            ?>

AS3

import flash.display.*;

import flash.events.*;

import flash.net.URLLoader;

import flash.net.URLRequest;

import flash.net.URLVariables;

import flash.net.URLLoaderDataFormat;

import flash.net.URLRequestMethod;

var phpVarsSession:URLVariables = new URLVariables();

var phpFileRequestSession:URLRequest = new URLRequest("adminPage.php");

phpFileRequestSession.method = URLRequestMethod.POST;

var phpLoaderSession:URLLoader = new URLLoader();

phpLoaderSession.dataFormat = URLLoaderDataFormat.VARIABLES;

phpLoaderSession.addEventListener(Event.COMPLETE, showSession);

phpVarsSession.user = user.text;

phpFileRequestSession.data = phpVarsSession;

phpLoaderSession.load(phpFileRequestSession);

function showSession(event:Event):void

user.text = "" + event.target.data.session;

}

This topic has been closed for replies.
Correct answer kglad

use:

adminPage.php (successpage)

<?php

session_start();

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

$username = $_POST['username'];

    print "session=$username";

            ?>

2 replies

kglad
Community Expert
Community Expert
February 1, 2013

copy and paste the trace output from:

AS3

import flash.display.*;

import flash.events.*;

import flash.net.URLLoader;

import flash.net.URLRequest;

import flash.net.URLVariables;

import flash.net.URLLoaderDataFormat;

import flash.net.URLRequestMethod;

var phpVarsSession:URLVariables = new URLVariables();

var phpFileRequestSession:URLRequest = new URLRequest("adminPage.php");

phpFileRequestSession.method = URLRequestMethod.POST;

var phpLoaderSession:URLLoader = new URLLoader();

phpLoaderSession.dataFormat = URLLoaderDataFormat.VARIABLES;

phpLoaderSession.addEventListener(Event.COMPLETE, showSession);

phpVarsSession.user = user.text;

trace("send",phpVarsSession.user);

phpFileRequestSession.data = phpVarsSession;

phpLoaderSession.load(phpFileRequestSession);

function showSession(event:Event):void

trace("received");

for(var s:String in event.target.data){

trace(s,event.target.data);

}

user.text = "" + event.target.data.session;

}

February 2, 2013

Nope. Didn't work. I've read from somewhere that the order of the session counts..I've tried it but it still doesn't work. But it's ok..it's not compulsory though, just trying to enhance my project. Haha.

kglad
Community Expert
Community Expert
February 2, 2013

you didn't follow my suggestion.

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
January 31, 2013

use:

adminPage.php (successpage)

<?php

session_start();

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

$username = $_POST['username'];

    print "session=$username";

            ?>

February 1, 2013

Hey, thanks for replying.

I did use the code you gave me but it's still undefined though. Maybe the actionscript is the problem?