Page 1 of 1

getting started Sample Quiz stack and FTP uploading

Posted: Wed Jan 09, 2008 4:14 pm
by reelstuff
Hello,

I was just playing around with the Quiz stack, in the sample projects, getting started.

While I am waiting on the Bundle deal to be delivered, I am excited about seeing some of those great apps.

I was wondering if anyone had successfully used the Quiz stack to upload results to FTP, It sort of looks like you would need some kind of custom handler.

which is not present, I would think you would need to either use a browser object, (not really practical) or to use shell on windows and mac to "put" the results into the specified FTP address,

I was able to connect using the appropriate string, but nothing seems to happen, so I looked a little deeper and did not see any specific method in use in this stack.

has anyone used this stack successfully and if so would you be willing to share how you were able to setup the ftp interface inside the stack.

any thoughts, suggestions, are always appreciated.

Tim

Posted: Wed Jan 09, 2008 6:55 pm
by BvG
I don't know what the quiz stack contains, but putting stuff on ftp is very easy with rev:

Code: Select all

on mouseUp
  put field "sometext" into url "ftp://user:password@yourserver.com/folder/morefolders/file.txt"
end mouseUp
things to look up:

url
ftp
entries that show up when you enter "libURL*ftp" in the docu

Posted: Wed Jan 09, 2008 7:07 pm
by reelstuff
BvG wrote:I don't know what the quiz stack contains, but putting stuff on ftp is very easy with rev:

Code: Select all

on mouseUp
  put field "sometext" into url "ftp://user:password@yourserver.com/folder/morefolders/file.txt"
end mouseUp
things to look up:

url
ftp
entries that show up when you enter "libURL*ftp" in the docu

Thank you, I believe I can see how it can be done now,

Posted: Wed Jan 09, 2008 8:52 pm
by malte
Hi Tim,

there are quite a few ways to communicate with the internet in Rev. Let me give you another real life example. If you want to build something like a highscore list that is viewable from the internet, you can use Revolution to communicate with a PHP Script on your server, which stores information like the Date, username and highscore in a Database on your Server and reads the data back to output some formatted HTML.

The scripts look like this:

Revolution part first:

Code: Select all

on mouseUp
  local tParam
  put check(line 1 of fld "userName",gScore) into tParam
  get url ("http://www.yoururl.com/highscore.php"&tParam)
end mouseUp

function check pName,pscore
  if "mac" is in the platform then
    put macToIso(pName) into pName
  end if
  local tCheck,tResult
  put md5Digest(pName&pscore&"magicWordOnlyYouKnow") into tCheck
  put URLEncode(pName) into pName
  get binarydecode("H*",tCheck,tResult)
  return "?name="&pname&"&score="&pscore&"&check="&tResult
end check
And the PHP Counterpart:

highscore.php

Code: Select all

<?php

/* Variables  */
$code_appendix = "magicWordOnlyYouKnow";					// String to attach before building MD5

/* Error Codes */
$name_hack_str = "name_hack";								// No Name in the params
$score_hack_str = "score_hack";							// No Scores in params
$check_hack_str = "check_hack";								// No checksum in params
$no_db_connection = "no_db_connection";						// Could not connect to DB
$db_write_error = "db_write_error";							// Could not write to DB
$entry_ok = "entry_ok";										// Successfully written


/* MYSQL Variables */
$mysql_server		= "yoururl.com";		// Serveraddress mySQL-DB
$mysql_db_name		= "DBXYZ";				// Name of mySql DB
$mysql_tbl_name		= "highscores";				// Name of Table
$mysql_user		= "yourUser";				// Database User
$mysql_passwort		= "Passwort";				// Database User

if(isset($_GET['name']))
	$name = htmlspecialchars($_GET['name']);
else
{
	echo $name_hack_str;					// No user specified
	exit();
}
	
if(isset($_GET['score']))
	$score = htmlspecialchars($_GET['score']);
else
{
	echo $score_hack_str;					// No Score specified
	exit();
}

if(isset($_GET['check']))
	$check = htmlspecialchars($_GET['check']);
else
{
	echo $check_hack_str;					// No checksum found
	exit();
}
	
$code = $name.$score.$code_appendix;
$code_md5 = md5($code);

if($code_md5 == $check)
{

	
	$datum = date("Y-m-d H:i:s");
	
	/* Write to DB */
	@$connection = mysql_connect($mysql_server,$mysql_user,$mysql_passwort) or die ($no_db_connection);
	$query_db = "INSERT INTO " .$mysql_tbl_name. "(name,score,datum) VALUES('" .$name. "','" .$score. "','" .$datum. "');";
	$result_db = mysql_db_query($mysql_db_name,$query_db,$connection) or die ($db_write_error);
	
	echo $entry_ok;
}
else
	echo $check_hack_str;					
?>
To display the things you have stored in your DB you can use something along these lines:

Code: Select all

<?php

$no_db_connection = "no_db_connection";						// Could not connect to DB
$db_view_error = "db_view_error";							// Could not read from Table


/* MYSQL Variablen */
$mysql_server		= "yoururl.com";		// Server with Database
$mysql_db_name		= "DBXYZ";				// Name of mySQL DB
$mysql_tbl_name		= "highscores";				// Name of Table
$mysql_user		= "yourUser";				// DB User Name
$mysql_passwort		= "Passwort";				// DB Password
?>

<html>
	<body>
		<table width="600px" border="0" cellspacing="5" cellpadding="0">
			<tr><td width="200px"><u>Name:</u></td><td width="200px"><u>Score:</u></td><td width="200px"><u>Date:</u></td>
			<tr><td width="200px">&nbsp;</td><td width="200px">&nbsp;</td><td width="200px">&nbsp;</td>
			<?php
				/* Read from DB */
				@$db_connection = mysql_connect($mysql_server,$mysql_user,$mysql_passwort) or die ($no_db_connection);
				$db_query = "SELECT * FROM " .$mysql_tbl_name. " ORDER BY score DESC LIMIT 100;";
				$db_result = mysql_db_query($mysql_db_name,$db_query,$db_connection) or die ($db_write_error);
				while($score = mysql_fetch_array($db_result, MYSQL_BOTH))
				{
					echo "<tr><td width=\"200px\">" .$score['name']. "</td><td width=\"200px\">" .$score['score']. "</td><td width=\"200px\">" .$score['datum']. "</td></tr>";
				}
			?>
		</table>
	</body>
</html>
Hope that helps,

malte

[edit]
fixed typo in varNames that slipped in while translating
[/edit]

Posted: Thu Jan 10, 2008 1:05 pm
by reelstuff
Wow, that is amazing, thank you for posting that information it opens up a lot of possibilities,

very interesting, examples, thank you