Jump to content

lporiginalg

New Members
  • Posts

    3
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

lporiginalg's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi there, I am new to the forum was really unsure where to post my thread since I have no idea where the issue in my application is actually coming from. I've put a flash game on facebook as a canvas app. Once a user authorizes my application I grab their name and id and then use the id to check if they already exist in my database. If they do I pull their score otherwise I add them into the db. Every browser and 3 different machines I have tried it on, and with multiple user accounts, it always works. I have never been able to reproduce the issue of the user not getting registered in the db, but facebook shows that about 28 people have authorized my app, but only 13 of them have been registered in the db. Some friends I asked to try the game told me they liked the game, and facebook says they played it, but they do not show up in my apps database. 13 out of 28 captured! It makes me wanna cry cause all those uncaptured users are not getting the proper experience. I'm using Amfphp framework to bridge flash and php. The app is hosted for free on Heroku and uses the free pgsql db they provide. The app can be seen here: http://apps.facebook...wordfighterbeta After the flash loads I call the AS3 API for facebook: import com.facebook.graph.Facebook; Facebook.init(APP_ID, onInit); //my app id is correctly set function onInit(result:Object, fail:Object):void { if (result) { Facebook.api("/me", getUserInfoHandler, null, "GET"); loggedIn = true; } else { resultTxt.text = "In order to save your highscores this app requires facebook authentication."; loginBtn.label = 'Facebook Login'; loginBtn.addEventListener(MouseEvent.CLICK, handleLoginClick, false, 0, true); loginBtn.enabled = true; } } //called when they click 'login' function handleLoginClick(event:MouseEvent):void { Facebook.login(onLogin); } function onLogin(result:Object, fail:Object):void { if (result) { Facebook.api("/me", getUserInfoHandler, null, "GET"); } else { resultTxt.text = "Authorization denied."; } } function getUserInfoHandler(result:Object, fail:Object):void { if (result) { userName = result.name; userID = result.id; registerUser(userID, userName); //this is where I try to add the user to the database } else { resultTxt.text = 'fail'; } } function registerUser(id, user):void { if (! local) { _netConnection = new NetConnection(); _netConnection.connect("https://sheltered-plateau-6639.herokuapp.com/Amfphp/"); _netConnection.call("WordFighter/registerUser", new Responder(handleResultArray, null), id,user); } } function handleResultArray(result:*):void { for each (var user:Object in result) { userScore = user.score; //start the game } And here is the registerUser function I wrote in PHP: public function registerUser($id, $name){ $host = "ec2-107-22-161-45.compute-1.amazonaws.com"; $user = "jytgyzybpoqjed"; $pass = "password"; $db = "dbvgstj2v06pit"; $con = pg_connect("host=$host dbname=$db user=$user password=$pass") or die ("Could not connect to server\n"); $query = "SELECT * FROM noobs WHERE fbID='$id'"; $rs = pg_query($con, $query) or die("Cannot execute query: $query\n"); if(pg_num_rows($rs) > 0){ $noobs = array(); $noobs[] = pg_fetch_assoc($rs); return $noobs; } else { $query = "INSERT INTO noobs (fbID, name, score) VALUES ('$id', '$name', '0')"; $rs = pg_query($query) or die("Cannot execute query: $query\n"); $query = "SELECT * FROM noobs WHERE fbID='$id'"; $rs = pg_query($query) or die("Cannot execute query: $query\n"); $noobs = array(); $noobs[] = pg_fetch_assoc($rs); return $noobs; } pg_close($con); } So yea. Who is the genius out there that can tell me why so many users aren't getting saved. The part that really confuses me is that when I look at the actionscript I see no way they can advance and play the game without the php returning an answer to the registerUser call since that's the only place in the code that starts the game, so why are some people playing the game and evading the database?
  2. Hi thanks for the replies guys. I tried your code jon but it seems to just name ever file "..jpg" and overwrite the file every time. I kind of need it to be letter names anyway. Guilty let me elaborate what I meant by session_id and again sorry if I'm off base or not explaining this properly as I don't know much about PHP, but basically I have a unique ID which is passed into the flash at runtime. Using loadVariables in actionscript I can pass this value to my upload.php script before sending the upload call. So in my PHP script I could have something like: $myID=$_POST['session_id']; And was wondering if there was then a way to have PHP check if this ID has been called before, if not it would call the first upload 'a.jpg' and if it had then it would somehow remember what the last given filename was for that id and move up accordingly? I'm not sure how it's suppose to remember that but...if anyone knows how to achieve what I'm going for, one way or another, that would be great. Jons code would have been sufficiently satisfactory had it worked and used letters instead of numbers. Every upload will be a seperate call to the PHP so maybe that's my problem cause there's no way for PHP to remember stuff from one call to the next? Thanks for all your help guys, hope we can figure this out. lp
  3. Hi Everyone I'm knew to this board. I'm highly proficient in actionscript but a bit noob in PHP. I'm working on a flash/php image uploader app and I'm a bit stuck on how to give the files the filenames I want. I need the files to be named a.jpg (or whatever the extension is), b.jpg, c.jpg etc.... I have a session_id which can be passed in from the flash as well so that for each session it should start with a.ext and move on from there and when a new session starts go back to 'a' But I'm not sure how to use the session_id to achieve this or make the file names go up. Here is the php code I'm currently using: <?php if(!is_dir("./files")) mkdir("./files", 0755); function findexts ($filename) { $filename = strtolower($filename) ; $exts = split("[/\\.]", $filename) ; $n = count($exts)-1; $exts = $exts[$n]; return $exts; } $ext = findexts ($_FILES['Filedata']['name']) ; $newfilename = a.".".$ext; move_uploaded_file($_FILES['Filedata']['tmp_name'], "./files/".$newfilename); chmod("./files/".$_FILES['Filedata']['name'], 0777); ?> Obviously there's some problems since this code just names every file to 'a.jpg' but it's about as far as I was able to get. If someone can show me how to use session_id and make the file names go down the alphabet sequentially that would be sooooo cool. Cheers, Lyndon
×
×
  • 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.