0

I have a php website that uses sessions and if your not logged in you cannot access a web page... I want the same for my Flash file, but want flash to see if there is a valid session on the php website and if there is play the flash, if not access denied..!

this if they download the flash file and are not logged into the PHP website they cannot play the file.


here is my PHP session I.D I want to use for validation from PHP to Flash..

$member = "{$_SESSION['SESS_MEMBER_ID']}";

here is my PHP authentication that runs on every page

//Start session
session_start();

//Check whether the session variable SESS_MEMBER_ID is present or not
if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID']) == '')) {
    header("location: access-denied.php");
    exit();
}
0

2 Answers 2

2

Create a PHP page that returns some url encoded variables based on their user session being set.

if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID']) == '')) {
    echo "&isLoggedIn=0";
}else{
    echo "&isLoggedIn=1";
}

Once your flash file is added to the stage, use a URLLoader to load the page and determine what to do based on its output:

private function handleAddedToStage(e:Event):void
{

    var loader:URLLoader = new URLLoader();
    loader.addEventListener(Event.COMPLETE,handleLoaded);
    loader.dataFormat = URLLoaderDataFormat.VARIABLES;
    loader.load(new URLRequest('http://my.domain.com/isloggedin.php'));

}

private function handleLoaded(e:Event):void
{
    var loader = e.target as URLLoader;

    if(loader.data.isLoggedIn == 1)
    {
        //  Run animation
        runAnimation();
    }
    else
    {
        //  show access denied
        showAccessDenied();
    }   
}
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you so much...... Will try it tonight and let you know how it goes... Thanks again..
Sure try it out and if you found this useful please mark it up.
Im getting the following errors, any help? The class or interface 'URLLoader' could not be loaded. Attribute used outside class. Syntax error.
Yep this is Actionscript 3. The concept should be the same for Actionscript 2 except you would probably use a LoadVars instead of URLLoader.
0

Actionscript 2.0 is pretty deprecated these days so my AS2 is a little rusty but hopefully this can get you going in the right direction:

private function applicationReady():Void
{
   var loader:LoadVars = new LoadVars();
   loader.onLoad = handleLoaded;
   loader.load("http://my.domain.com/isloggedin.php");
}

private function handleLoaded(success:Boolean)
{
    if( success && this.isLoggedIn==1)
    {        
        //  Run animation
        runAnimation();
    }
    else
    {
        //  show access denied
        showAccessDenied();
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.