PHP advanced login through flash

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bdavey311
Forum Newbie
Posts: 2
Joined: Fri Nov 07, 2008 1:03 pm

PHP advanced login through flash

Post by bdavey311 »

I've set up a Login screen in Flash that commicates through PHP to check if the user name and password match before it advances to the secret part of the flash file. Now!

My question is: I want to enable different users to view only certain areas of the Flash piece. I've been told that I can use "ID " numbers from my sql and change the label in flash with ID Numbers.

Is this true and how can I make this work?

Here is the PHP:

Code: Select all

<?php 
 
if(isset($_POST['user'])) 
{ 
    $user = $_POST['user']; 
    $pass = $_POST['pass']; 
 
    mysql_connect("domain.net","domain","domain") or die ("didn't connect to mysql"); 
    mysql_select_db("domain") or die ("no database"); 
 
    $query = "SELECT * FROM auth WHERE username = '$user' && userpassword = '$pass'"; 
    $result = mysql_query($query) or die ("didn't query"); 
 
    $num = mysql_num_rows($result); 
 
    if($num == 1) 
    { 
        echo "checklog=1&status=Logged in successfully"; 
    }  
    else { 
    echo "checklog=2&status=Insufficient username and password"; 
    } 
} else { 
    echo "Error"; 
} 
 
?>
And for giggles - Here is the Flash Actionscript:

Code: Select all

stop();
 
// Create 2 LoadVars objects to load and send data to the PHP script
var loader:LoadVars = new LoadVars();
var sender:LoadVars = new LoadVars();
 
status = "Enter your information and submit";
 
// When the submit button is pressed...
submit_btn.onRelease = function() {
    // assign the text in the input fields to the sender object
    sender.user = userinput.text;
    sender.pass = passinput.text;
    _parent.gotoAndStop("Success");
    
    // and then send it on to the PHP file on the server using
    // the POST method.  The returned result will be caught
    // by the loader object
    sender.sendAndLoad("newlogin.php", loader, "POST");
}
 
// The loader object waits for a response from the server
// and checks for any returned variables, messages, errors.
loader.onLoad = function(success:Boolean)
{
    // This boolean variable (success) will return true or false
    // on whether the PHP file was retrieved
    if(success)
    {
        // If we're here then we've successfully retrieved
        // the PHP file.  Lets check for a Login result
        if(this.checklog == 1)
        {
            // This is a authorised login so show the success frame
            // and show the message in the status textfield
            status = this.status;
            _parent.gotoAndStop("Success");
        }
        else if(this.checklog == 2)
        {
            // This is a unauthorised login so show the failure frame
            // and show the error message in the status textfield
            status = this.status;
            _parent.gotoAndStop("Invalid");
        }
    }
    else {
        // There was a problem retrieving the PHP file
        status = "Error connecting to server";
    }
}
And here is the progress of the post at a different forum:
http://www.actionscript.org/forums/show ... post810543

Unfortunately I have very little knowledge about all of this.

Little help and thanks in advance!
Brian
Post Reply