PDA

View Full Version : Flash and PHP sessions



btgon
April 14th, 2004, 05:31 PM
Hi all. I am a little new to flash and designing a flash menu for a project. The site is written in PHP and the Flash menu will just be at the top of the page. Thanks to the tutorial I know there is a way to place login fields in the Flash menu, but I was wondering if Flash can then assign " $_SESSION['user'] " a variable that can be read by the main PHP page.

I created a quick Flash movie that connects to a PHP service that does this :

function getLogin() {

$user = "btgon";

$_SESSION['user'] = $user ;

$myresult = $_SESSION['user'];

return trim($myresult);

}


The Flash movie displays "btgon" so I know session user is created, but when I insert the Flash movie in a PHP file, it doesn't see the session user at all. I am sure someone has tried this before, any help would be greatly appreciated!

Lost
April 14th, 2004, 05:36 PM
session_start();

duh;

btgon
April 14th, 2004, 05:37 PM
lol, forgot to include that in the clip I posted... but it is there at the very top!


<?

session_start ();

// class for LognService code removed for space.

function getLogin() {

$user = "btgon";

//session_register ('user');
$_SESSION['user'] = $user ;

$myresult = $_SESSION['user'];

return trim($myresult);

}

Hans Kilian
April 15th, 2004, 04:15 AM
You say "I was wondering if Flash can then assign " $_SESSION['user'] " a variable that can be read by the main PHP page".
The short answer to that is no. Flash and PHP don't share variable spaces, so there's no way to simply set a variable in Flash and have PHP get that value. You have to set up some form of communication to send the value from Flash to PHP.

You sound as if you already have a way to execute your PHP script from your Flash movie. You could then easily send the user name from Flash to PHP by appending '?user=<userid>' to the URL of the PHP script. So if the user name is 'Hans', your URL would be something like phpscript.php?user=Hans.

Then in your PHP script, the user name will be available in the variable $_GET['user'] and you can set $_SESSION['user'] = $_GET['user'].

I hope that helps. If not, then ask some more.

btgon
April 15th, 2004, 03:06 PM
Thank you Hans Kilian for you help! I am kinda disappointed to learn that Flash and PHP can't share a variable. While your suggestion would work, it wouldn't do much for security! At that point couldn't anyone just enter the direct url and get into a users information? Is there anyway to prevent this?