PDA

View Full Version : Pass Flash variable to PHP


JasonWilliams
05-28-2007, 10:57 PM
Hey all,

I'm quite new with PHP and have no experience with Flash - but know someone who does, I've designed a system for forums (VBulletin) to stop spammers signing up - but it can be defeated, I was planning to make it out of flash instead of using image links - that should be harder if not impossible to overcome, but I don't quite know what is the best way to pass the variable from Flash to PHP to be interpreted as a right or wrong answer.

Is there any easy way around this?

Cheers

Jason

sonicdoomx
06-02-2007, 12:48 PM
Hi, let me try help you out.

Actionscript

var result_lv:LoadVars = new LoadVars();
result_lv.onLoad = function(success:Boolean) {
// What you do with the result generated from php
if(this.success == "true"){
//if succesful
}else{
//if not succesful
}
};
var send_lv:LoadVars = new LoadVars();
//Here you insert variables to be sent (example using username and password)
send_lv.user = usernameBox.text;
send_lv.pass = passwordBox.text;
//this will send the variables and get the result
send_lv.sendAndLoad("http://localhost/login.php", result_lv, "POST");


PHP

//this gets your variables from flash
$user=$_POST['user'];

mysql_select_db($database_example, $Test);
$query_Credentials = sprintf("SELECT password FROM users WHERE username = '%s'", $user);
$Credentials = mysql_query($query_Credentials, $Test) or die(mysql_error());
$row_Credentials = mysql_fetch_assoc($Credentials);
$totalRows_Credentials = mysql_num_rows($Credentials);

//this gets your variables from flash
$pass=$_POST['pass'];

//this prints out results for you to process with flash
if($row_Credentials['password'] == $pass){
echo "success=true";
}else{
echo "success=false";
}
mysql_free_result($Credentials);


Hope it helps. Cheers.

JasonWilliams
06-28-2007, 03:01 PM
Thank you - I will give that a try and see how it goes .... looks fairly straightforward :D

Cheers

Jason