You don’t need PUT or POST to write - that’s a convention, but it’s only necessary if you’re trying to make "REST"ful websites and such. What you need is appropriate server-side code.
So - here’s a simple example. Note that it does NOT do many things you’d want to do in the real world, like preventing someone from spoofing it, but it should be good enough to explore the concept. This should run in any semi-modern perl - if you’re on windows, you’ll want to change the “dbmopen” line to reflect your drive setup. If you have an older perl, the CGI module won’t be built-in - go get a new perl, dude.
#!/usr/bin/perl
use CGI qw(:standard);
$name = param("name"); $name =~ s/[^\\w]//g;
$score = param("score"); $score =~ s/[^\\d]//g;
dbmopen(%SCORE, '/var/tmp/scores', 0666);
if (($name eq '') and ($score eq '')) { # no name or score, return list
print "Content-type: text/plain\
\
";
foreach (sort keys %SCORE) {
print "$_ = $SCORE{$_}\
";
}
dbmclose(%SCORE);
exit;
}
$SCORE{$name} = $score;
dbmclose(%SCORE);
print "Content-type: text/plain\
\
$name = $score\
";
exit;
For messing around with - I have this up and running at http://home.bortels.us/hiscore.cgi (and will until it gets abused) - go ahead and hit that link for a list of high scores. You can add to them by adding parameters to your http call: http://home.bortels.us/hiscore.cgi?name=Fred&score=17 would give “Fred” a score of “17”.
It’s up to your Codea script to parse and display the results, of course.
In a “real” implementation, you’d want to figure out some way to try to prevent spoofing (good luck with that, really), and to have the server do a “top scores” list for you rather than downloading them all - perhaps have it sort as well. You might want to make it support multiple games as well (I had that, for a bit, but it complicated things) That’s left as an exercise to the reader.
One bit of advice - see the “=~” sections at the top, where name and score are assigned? Those strip out non-word (for name) and non-number (for score) entries. If you don’t have that sort of thing, you open yourself up to ugly cross-site scripting attacks. Be VERY careful messing with server side stuff - it’s easy to open yourself wide open to various attacks, especially if you re-display the data sent. Also be aware that if you get popular, the simple perl cgi above could (would!) easily crumple under real load. Fair warning.