Limit variables on Flash with PHP
- June 22nd, 2008
- Write comment
I was working with login script using the usual code I used to use for always
loadVariableNum(“test.php”,0,”POST”);
kinda nice but wait wait wait, what is this doing? loading all the root variables and spreading php variables on root randomly, HELL that is a real mess? it even didnt work in some cases (like my case today with my XML Flash file)
but yes as usual alot of search and alot of do. I got it to work perfectly with this very very clean code
Send and Load (To send specific variables to PHP) and Get Specific one back.
so here it is
on (release, keyPress “
“) {
if (_root.user != “” && _root.pass != “”) {
_root.text=”Connecting..”;
//result_lv to get variables from php
var result_lv:LoadVars = new LoadVars();
//set_lv to post variables to php
var set_lv:LoadVars = new LoadVars();
set_lv.user = _level0.user;
set_lv.pass = _level0.pass;
set_lv.sendAndLoad(“newlogin.php”,result_lv,”POST”);
result_lv.onLoad = function(success:Boolean) {
if (success) {
if (result_lv.checklog == 1) {
_root.text=”Congrat you are logged”;
}
else
{
_root.text=”Sorry no such user name or password”;
}} else {
_root.text=”Could Not Connect”;}
};
}
}
I know this is flash thing but if you still curious about the php part then here it is
$user=$_POST['user'];
$pass=$_POST['pass'];
if ($user && $pass){
mysql_connect(“localhost”,”root”,”");
mysql_select_db(“database”);$query = “SELECT * FROM users WHERE username = ‘$user’ AND password = md5(‘$pass’)”;
$result = mysql_query( $query ) ;$num = mysql_num_rows( $result );
if ($num == 1){
print “status=You’re in&checklog=1″;
} else {
print “status=Sorry!&checklog=2″;
}
}