Search tutorials
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 |
» Author |
Cycling, snowboarding, flash creator extraordinaire. |
» Download |
Download the files used in this tutorial. |
Download (21 kb) |
» Forums |
More help? Search our boards for quick answers! |