I have a Flash game which I want people to play once, but then if they tried to play the game again, it would prompt them to register first. Once registered, the user has to login if they want to play the game over and over.

Login page:
1. Sets a (traditional browser) cookie based on the username.

Flash game page:
1. If the cookie from above exists, a query is made to the database to retrieve the users information.

2. I've added 2 (querystring) variables to the Flash game code - one for the members ID, and the Nickname of the user. I.e. this info is passed to the Flash game, like so:
value="flashgame.swf?nickname=<?php echo $usersNickname; ?>&memberID=<?php echo $usersMemberID; ?>"

3. In the game, I've also created a "Flash cookie", like so:


This code is at the end of the game, meaning if you've reached this far, you've played the game at least once.

4. So, at the beginning of the game I have added this code, so it checks to see the value of the "SharedObject" :

if (mySharedObject.data.playedOnce==true && ((_root.memberID<=1) || (_root.memberID==null))){
gotoAndStop("registerpls"); // ...so show register message
} else {
trace("Can't find any trace of the player having played the game yet!");

In the code above, I've also added a check for the value of the memberID, to see if it is 1 or lower (i.e. that would mean the user is not logged in because all the memberIDs are above 1).

However - the problem is this check is not working because the user isn't redirected to the register message at the start of the game.
Instead, it lets the user play the game again and THEN prompts them to register only at the end of the game.

Any ideas why this is?


On a seperate note, I want to delete the cookie when the user has logged out, but it doesn't delete the cookie for some reason!

Part 1 of the code creates the cookie when logging in:
if (isset($HTTP_POST_VARS['username'])) {
setcookie("myCookie", $HTTP_POST_VARS['username'], time()+86400*365);

Part 2 of the code is the logout code:
//initialize the session

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
$logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
//to fully log out a visitor we need to clear the session varialbles

// delete the cookie when logging out
setcookie("myCookie", "", time()-90000*365);

$logoutGoTo = "../index.php";
if ($logoutGoTo) {
header("Location: $logoutGoTo");

Part 2 of the code is the link itself:
echo '<a href="'. $logoutAction. '" target="_self">Logout</a>';