Jump to content

Flash to PHP interaction


ILYAS415

Recommended Posts

Okay ive been playing around with a flash game which i created.

The game is integrated into an arcade for a text-based game.

 

Okay basically im trying to get the end scores for the game and send them to a php script.

The php script is then meant to process the score and see if the player is worthy enough to be credited money in the actual text-based game.

 

Heres the code which is meant to send information to the php script:

_root.finalscore=_root.score;

var receiver_lv:LoadVars = new LoadVars();
receiver_lv.onLoad = function(ok){
      if(ok){
           message.text = receiver_lv.message;
	   score = _root.score;
	   getURL("flashtophp1.php", this, "POST");
      }else{
           message.text = "There was an error!!";
      }
}
receiver_lv.load("flashtophp1.php");

 

Okay and heres the php script which then processes it:

<?
$username= $_SESSION['username'];

$score= $_POST['score'];
//OKAY THE PROBLEM IS THAT THE SCRIPT READS THE POST VAR AS EMPTY
if ($score < "100"){
$msg="You need 100 to win a prize! your score was $score $username";
}else{
$money= $score*5;
$msg="You earned £$money ".ucfirst($username)."";
mysql_query("UPDATE users SET money=money+'$money' WHERE username='$username'");
}

echo "&message=$msg $score";
?>

Well the problem is that the $_POST['score'] var is empty.

Link to comment
https://forums.phpfreaks.com/topic/90266-flash-to-php-interaction/
Share on other sites

i don't know if this is what you really want, but couldn't u put the score in the url and then just get it using php.

 

flashtophp1.php?score=125

 

$score = $_GET['score'];

then carry on?

 

That method is always possible, but with the $_POST you have less of a security risk.

To get data into your Flash application you can you XML sockets. One of the first big things I made in Flash used Flash sockets to communicate to a C++ socket server. However you do it, I would recommend against using Javascript - just introduces too many browser support issues.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.