Flash: play game once only and then register - how to?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Flash: play game once only and then register - how to?

Hybrid View

  1. #1
    Join Date
    Dec 2004
    Posts
    64

    Question Flash: play game once only and then register - how to?

    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:

    mySharedObject=SharedObject.getLocal("userData");
    mySharedObject.data.playedOnce=true;
    mySharedObject.flush();

    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:
    <?php
    if (isset($HTTP_POST_VARS['username'])) {
    setcookie("myCookie", $HTTP_POST_VARS['username'], time()+86400*365);
    }
    ?>

    Part 2 of the code is the logout code:
    <?php
    //initialize the session
    session_start();

    // ** 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
    session_unregister('MM_Username');
    session_unregister('MM_UserGroup');

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

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

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

    Thanks.

  2. #2
    Join Date
    Dec 2004
    Posts
    64
    I think part of the problem may be the Flash movie itself being taken from the browser cache - so it nearly always has the memberID and nickname in memory - this would explain why even though no one is logged in, the checks in Flash always return false, thinking someone IS logged in and letting them play over and over!

    I could use a "meta pragma nocache tag" in the flash page, but is there another way of stopping the movie being cached, perhaps in the flash html code itself?

  3. #3
    Join Date
    Dec 2004
    Posts
    64
    I added header tags to disable the cache on the flash game page, but no luck - the Flash movie still shows the cached variables even though they are empty! How annoying is that?!

  4. #4
    Join Date
    Dec 2004
    Posts
    64

    Unhappy Fixed Flash variables, but PHP cookie deletion still not working

    I fixed the problem re the variables not refreshing correctly in flash - remove the querystring on the flashname, and add a new parameter called "flashvars". This also prevents the user from having to download the flash game everytime it is played.

    BUT - I still cannot successfully delete a cookie (using PHP) from my system on logout!! Has anyone got any ideas as to why this is not working??

    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center