PDA

View Full Version : Flash to PHP advanced login



bdavey311
November 6th, 2008, 05:16 PM
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.

"Success" would be the frame label, so could I have Success1, Success2, Success 3, Success 4 that can then tell flash what frame label to go to to play the relevent movieClip for that particular user?

Here is the PHP:


<?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";
}

?>

This is the actionscript in the Flash file:
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";
}
}

Hopefully this would be an easy addition. Thanks in advance!

Brian

danielelvito
November 6th, 2008, 06:43 PM
I think you can use "ID " numbers from your sql elsewhere "success" and change your label in your flash with ID Numbers :+) :look: