Forums
This topic is locked
flash, PHP sessions problem
Posted 18 Nov 2005 03:38:25
1
has voted
18 Nov 2005 03:38:25 steve donovan posted:
Hello, I am a newbie to Flash and PHP trying to get a flash login form to work.
There are two methods in place to login to protected areas of the site: through a
Flash form on the left side of pages, or via an html page called login.php.
Loggin in works fine with the html form, but with the flash form the session variable
doesn' seem to get set unless I log in twice.
In my Flash file I have an action for the "enter" button that looks like:
on (release) {
protected_home = "protected/home.php";
loginURL = "protected/flash_login.php";
this.createEmptyMovieClip("target_mc", this.getNextHighestDepth());
loadVariables(loginURL, target_mc, "POST"
function checkLoaded() {
if (target_mc.valid_flag == undefined) {
} else {
clearInterval(param_interval);
if (target_mc.valid_flag == "true" {
getURL(protected_home);
} else {
gotoAndPlay(70);
}
}
}
var param_interval:Number = setInterval(checkLoaded, 100);
}
"flash_login.php" looks like:
<?php
if (!isset($_SESSION)) {
session_start();
}
$rString = "";
mysql_select_db($database_authorization, $authorization);
// Verify Login is correct
$query_rsLogin = sprintf("SELECT userName, userPassword FROM users WHERE userName = %s AND userPassword = PASSWORD(%s)",
quote_smart($HTTP_POST_VARS['user']),
quote_smart($HTTP_POST_VARS['pass']));
$rsLogin = mysql_query($query_rsLogin, $authorization) or die(mysql_error());
$row_rsLogin = mysql_fetch_assoc($rsLogin);
$totalRows_rsLogin = mysql_num_rows($rsLogin);
if($totalRows_rsLogin==0){
$rString .= "&valid_flag=false";
printf("%s", $rString);
mysql_free_result($rsLogin);
} else {
mysql_free_result($rsLogin);
$HTTP_SESSION_VARS['rw_username'] = $HTTP_POST_VARS['user'];
$rString .= "&valid_flag=true";
printf("%s", $rString);
}
?>
And, finally, protected pages begin with:
<?php
if (!isset($_SESSION)) {
session_start();
}
$loginURL = "login.php";
// session variable is set with username after successfull login
// stored in session variable
if (!(isset($_SESSION['rw_username']))) {
$querryChar = "?";
$referrer = $_SERVER['PHP_SELF'];
if (strpos($loginURL, "?") $querryChar = "&";
if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)
$referrer .= "?" . $QUERY_STRING;
$loginURL = $loginURL. $querryChar . "accesscheck=" . urlencode($referrer);
header("Location: ". $loginURL);
exit;
}
?>
Again, this works fine with the html login form, but from the Flash form
I always get redirected to "login.php" If I then hit the backbutton and
fill out the flash form again, I get through to "protected/home.php" and
am logged in just fine.
Anyone know what I am doing wrong?