dcsimg
First time here? First time here? Newsletter Signup Newsletter
Search tutorials
Author: Alan Wisternoff | Website: http://www.buffoonbrothers.com

The php

If you were going to design and HTML only login your php files would be very complicated. This is because HTML is dumb therefore all the smart stuff (checking for illegal characters, comparing inputed passwords, checking fields are filled in etc...) is done by the php file. But we use Flash, and Flash is smart. We will get Flash to do all these things and keep our php files uncluttered. We need two php files.

register

host address","username","password") or die();
mysql_select_db("database name") or die();
$usercheck = $_POST['username'];
$check = mysql_query("SELECT username FROM users WHERE username = '$usercheck'")
or die();
$check2 = mysql_num_rows($check);
if ($check2 != 0) {
print "words=Username already exists.&checklog=1";
die();
}
$insert = "INSERT INTO users (username, password)
VALUES ('".$_POST['username']."', '".$_POST['pass']."')";
$add_member = mysql_query($insert);
print "words=You are registered.&checklog=2";
die();
?>

login

mysql_connect("host address","username","password") or die();
mysql_select_db("database name") or die();
$check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die();
$check2 = mysql_num_rows($check);
if ($check2 == 0) {
print "words=User doesn't exist.&checklog=3";
die();
}
while($info = mysql_fetch_array( $check ))
{
if ($_POST['pass'] != $info['password']) {
print "words=Incorrect Password.&checklog=4";
die();
}else
{
print "words=You are logged in.&checklog=5";
die();
}
}
?>

The information in red you must substitute for your own information. Quite often your host address will be "localhost" but you will need to check. Obviously "username" and "password" are the login details for your mySQL database, and "database name" is its name (note this is not "users", that is the table name). Make sure you name the files, "register.php" and "login.php" respectively. This isn't a php tutorial so I will only explain the bits that relate to Flash. The flash document will send two variables, "username" and "pass" and the php files will deal with them accordingly. You can see in the code certain "print" commands. These variables are sent back to the swf file. You can use this information in your flash file anyway you wish. I use all the "words" variables as feedback for the user. I also use the checklog=5 variable, to tell the swf that login has been successful.

» Level Intermediate

Added: 2007-02-03
Rating: 7.43 Votes: 23
(10 being the highest)
» Author
Cycling, snowboarding, flash creator extraordinaire.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!

Comments

  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops
Image for equalize

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.