dcsimg
A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: [Help] Highscores/Php problem

  1. #1
    n00b LeechmasterB's Avatar
    Join Date
    May 2004
    Location
    Switzerland
    Posts
    1,067

    [Help] Highscores/Php problem

    Hello everyone,
    I have a small problem with a highscore board. The situation is this:
    The game is hosted on newgrounds.com and the highscore php file ect is placed on my site. Now if i have the swf file on my site in the game folder with the php it all works fine. But when i try saving from my harddrive or newgrounds it does not save at all. All it does is send the score to the php which reads the old scores and places it in the score list and sends it back to the swf. But new scores dont get stored into the data base file from the php. To be able to read the scores from newgrounds i had to use a crossconnection.xml and load the policy in the swf. Just how can i save through the php when the swf is not in the same folder and run from anywhere else?

    The score board is made after the glen rhodes tutorial you can find here on the site.

    Php file:

    Code:
    <?php
    
    	$winscore = (int)$winscore;
    
    	// Create a Blank File if it doesn't already exist
    	if (!file_exists($filename))
    	{
    		$file=fopen($filename, "w");
    		fclose ($file);
    	}
    
    	// Read the file in
    	$oscores = file ($filename);
    	$numreadin = count($oscores);
    
    	// Break out the data into a new 2-d array called $tscores
    	for ($i = 0; $i < $numreadin; $i++)
    	{
    		$g = unserialize($oscores[$i]);
    		$tscores[$i][0] = $g[0];
    		$tscores[$i][1] = $g[1];
    	}
    
    	// Fill in any missing data with none/0
    	for ($i = $numreadin; $i < $scoresize; $i++)
    	{
    		$tscores[$i][0] = 0;
    		$tscores[$i][1] = "";
    	}
    
    	// Process the actions	
    
    	// Insert a score/name
    	if ($action == "INSERT")
    	{
    
    		// Add name to end of list, and sort
    		$tscores[$scoresize + 1][0] = $winscore;
    		$tscores[$scoresize + 1][1] = $winname;
    		rsort ($tscores);
    
    		$file=fopen($filename, "w");
    
    		// Write them out
    		for ($i = 0; $i < $scoresize; $i++)
    		{
    			$st = serialize($tscores[$i]) . "\n";
    			fputs($file, $st);
    		}
    
    		fclose($file);
    	}
    
    	// Clear the list	
    	if ($action == "CLEAR")
    	{
    
    		$k[0] = 0;
    		$k[1] = "no-one";
    		$ser = serialize($k);
    
    		$file=fopen($filename, "w");
    
    		for ($i = 0; $i < $scoresize; $i++)
    		{
    			$st = $ser . "\n";
    			fputs($file, $st);
    		}
    
    		fclose($file);
    	}
    
    	// Process the OUTPUT options
    	if ($viewtype == "HTML")
    	{
    	  // HTML PAGE CREATED HERE
    	  ?>
    
    
    		
    <table cellpadding=2 cellspacing=2 border=0 width="330">
      <tr align=center> 
        <th bgcolor="#663300" width="80"><font color="#ffff00" face="Arial, Helvetica, sans-serif" size="1">Rank</font></th>
        <th bgcolor="#663300" width="126"><font color="#FFFF00" face="Arial, Helvetica, sans-serif" size="1">Name</font></th>
        <th bgcolor="#663300" width="104"><font color="#FFFF00" face="Arial, Helvetica, sans-serif" size="1">Score</font></th>
      </tr>
      <?
    	
    		for ($i = 0; $i < $scoresize; $i++)
    		{
    			echo ("<tr bgcolor='#669933' align='center'><td><font size='1' face='Arial, Helvetica, sans-serif'>");
    			echo ($i + 1);
    			echo ("</font></td><td><font size='1' face='Arial, Helvetica, sans-serif'>");
    			echo ($tscores[$i][1]);
    			echo ("</font></td><td><font size='1' face='Arial, Helvetica, sans-serif'>");
    			echo ($tscores[$i][0]);
    			echo ("</font></td></tr>");
    		}
    
      	  ?>
    </table>
    	  <?
    
    	}
    
    	// FLASH DATA CREATED HERE
    	if ($viewtype == "FLASH")
    	{
    		for ($i = 0; $i < $scoresize; $i++)
    		{
    			echo ("name" . $i . "=");
    			echo ($tscores[$i][1]);
    			echo ("&score" . $i . "=");
    			echo ($tscores[$i][0]);
    			echo ("&");
    		}
    	}
    
    ?>

    Code in game to save/load:

    Code:
    System.security.loadPolicyFile("http://www.dubhdroiacht.ch/cgi-bin/novenda/crossdomain.xml");
    System.security.loadPolicyFile("http://www.dubhdroiacht.ch/crossdomain.xml");
    System.security.loadPolicyFile("http://dubhdroiacht.ch/cgi-bin/novenda/crossdomain.xml");
    System.security.loadPolicyFile("http://dubhdroiacht.ch/crossdomain.xml");
    _global.domainName = "http://dubhdroiacht.ch/cgi-bin/novenda/";
    and

    Code:
    	/************/	
    	_root.filename = _global.domainName+"scores/highscores.sco";
    	_root.scoresize = 20;
    	_root.action = "INSERT";
    	_root.viewtype = "FLASH";
    	_root.winname = _root.name;
    	_root.winscore = _root.score;
    	_root.loadVariables(_global.domainName+"scores.php", "GET");
    	gotoAndStop("highScores1");
    I would be glad if anyone could help me get this to work.

    Edit: VengeanceMX if you read this, may be you have experience with highscores and newgrounds?

    greets
    Last edited by LeechmasterB; 02-10-2006 at 01:26 PM.
    I do stuff that does stuff...

    J-Force

  2. #2
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,227
    Maybe it works if you give the filename without full path:
    _root.filename = "scores/highscores.sco";

  3. #3
    n00b LeechmasterB's Avatar
    Join Date
    May 2004
    Location
    Switzerland
    Posts
    1,067
    Thank you tonypa, but i already have the full path added:

    _global.domainName = "http://dubhdroiacht.ch/cgi-bin/novenda/";

    Is the path and:

    _root.filename = _global.domainName+"scores/highscores.sco";

    the filename with path... it works with the swf in the same folder as the php file, the highscores.sco is in a subfolder. But i need to get it working outside of my site.
    I do stuff that does stuff...

    J-Force

  4. #4
    Senior Member UnknownGuy's Avatar
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    1,367
    Just as a general suggestion, you might want to check on any security issues.

  5. #5
    Script kiddie VENGEANCE MX's Avatar
    Join Date
    Jun 2004
    Location
    England
    Posts
    2,590
    Not sure whether or not it was PHP that was used, but some guy on NG has had server-side scripts in their Flash game before:

    http://www.newgrounds.com/portal/view/213147

    Perhaps you could email the author and ask how he did it?
    http://www.birchlabs.co.uk/
    You know you want to.

  6. #6
    Senior Member Gloo pot's Avatar
    Join Date
    Aug 2005
    Location
    Australia Mate!
    Posts
    874
    [off topic]
    That cursor theif is so dam kewl, its so funny watching him try and jump for my cursor.
    [/off topic]
    92.7 Fresh FM for all your South Aussies - Doof Doof music FTW people!

  7. #7
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,227
    Leech, when swf is in NG, you can read scores, but new scores are not saved?

  8. #8
    n00b LeechmasterB's Avatar
    Join Date
    May 2004
    Location
    Switzerland
    Posts
    1,067
    Thank you VENGEANCE MX, i will try asking him and may be he has an idea.



    Quote Originally Posted by tonypa
    Leech, when swf is in NG, you can read scores, but new scores are not saved?
    Yes, but also when the swf is on my harddrive for example. Just as soon as its not on my webserver you cant save the scores anymore. But loading works from everywhere...


    Thank you all for the effort so far!

    greets
    I do stuff that does stuff...

    J-Force

  9. #9
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,227
    Maybe you need to modify the permissions on php/sco files.

  10. #10
    n00b LeechmasterB's Avatar
    Join Date
    May 2004
    Location
    Switzerland
    Posts
    1,067
    Quote Originally Posted by tonypa
    Maybe you need to modify the permissions on php/sco files.
    Do you mean chmod or the swf policies?


    CHMOD 777 is set for the php file and the highscores.sco . The highscores work if you play it from this link:

    http://www.dubhdroiacht.ch/cgi-bin/novenda/

    but here they can only be read:

    http://www.newgrounds.com/portal/view/294219

    So there are file access and write rights set on the server, i put a crossdomain.xml into the root the folder containing the swf and the scores folder on the site. I load the plolicies in the swf before calling the highscores list via loadvars. Now i also added the system security allowdomain command in the swf. Could there be a way that the php only can write if its called from within the same folder? Or is there a way to let a php write stuff into a file on the same server by sending variables from another domain...?

    So if someone could get the saving work on a local drive same as when its run on a server it should work.

    Or may be thats not possible because of the properties set when publishing the file. local playback security is set to: Access local files only .

    But actually i think it cant be a problem with the swf itself and must be php or server related.

    Edit: Strange, now they dont work on my site anymore either .
    Last edited by LeechmasterB; 02-11-2006 at 08:20 AM.
    I do stuff that does stuff...

    J-Force

  11. #11
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,227
    Perhaps check chmod on scores folder too.

    P.S. Game does not even load from your site.

  12. #12
    n00b LeechmasterB's Avatar
    Join Date
    May 2004
    Location
    Switzerland
    Posts
    1,067
    The novenda folder and all subfolders -> domain/novenda/scores/ ect have chmod 777 activated.

    I had to rush out of the house and could not upload the index file... so it did not work until i got back to fix it. Now i am trying some varius settings until i get it at least to work on my site again (hopefully).
    I do stuff that does stuff...

    J-Force

  13. #13
    n00b LeechmasterB's Avatar
    Join Date
    May 2004
    Location
    Switzerland
    Posts
    1,067
    Hey thank you all for your precious time!! I got it to work, it were small things that had to change:

    The domain name has to contain www for the loadvars url, but not for the security policies (wierd)
    _global.domainName = "http://www.dubhdroiacht.ch/cgi-bin/novenda/";
    the filename needs to be local.. (without root) for the php file
    _root.filename = "scores/highscores2.sco";

    and the last thing is that the "local playback security" has to be set on access local files only. Now it works from anywhere, my harddrive, the site and newgrounds . YAY!
    I do stuff that does stuff...

    J-Force

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center