Read / write a text file from a web site

BlitzMax Forums/BlitzMax Beginners Area/Read / write a text file from a web site

hub(Posted 2010) [#1]
Hi !
My goal is to write data inside the scores.txt file.
The Ecrire_tableau_scores() not work ! Could you help me (no error messages!)! (the scores file and folder have the chmod to 777 to test !) Try this ! And tell me if you don't see any error inside this program. So i could check if this is a server / webhost issue !



Last edited 2010

Last edited 2010

Last edited 2010


hub(Posted 2010) [#2]
Any help about this ? perhaps i should translate the french expressions inside this code ?


degac(Posted 2010) [#3]
From my experiments I'm sure you can GET a file from net (via ReadStream(http::mydomain/file.txt)) without problems, but to send to a remote server you need to exchange info about user/password and so on.
Do a search in the code archives for other info

here a first step, for a FTP engine (the File Transfer Protocol you need)

http://www.blitzbasic.com/codearcs/codearcs.php?code=2090

Cheers


hub(Posted 2010) [#4]
but to send to a remote server you need to exchange info about user/password and so on.

of course ! i'm silly. Thanks !


xlsior(Posted 2010) [#5]
Using FTP would seem a bad idea: username/password info is transmitted in clear text, and very easily visible in many firewall logs to people. That would enable them to upload pretty much anything to your FTP server, and it would be a matter of time before people are using it to exchange all kinds of other files. (I used to work for an ISP, and we'd run into hijacked FTP sites all the time there)

You really need a 'proper' mechanism to update the scores, such as having the client call a PHP/ASP/CGI script on the server that accepts some necessary fields like name/score, as well as some kind of validation code so it can double-check that the submission was legit (e.g. your app can calculate a value based on the score and name, and encode the info in a variable. The server-side program can perform the same operation, and see if the value matches. That way you can prevent people from manually submitting fake highscore data)


xlsior(Posted 2010) [#6]
By the way: I don't know what platform you're trying to do this for, but if your game is windows-only there's already a pretty good library out there that can do web-based highscore tables: search the forum for the 'ETNA' library.


hub(Posted 2010) [#7]
Perhaps this : http://www.blitzbasic.com/codearcs/codearcs.php?code=1579 from code archive mix between php, mysql and blitzmax code.


hub(Posted 2010) [#8]
i've not read the previous code archive link yet, but is there a way to just send a 'quiet' query with bmax. like 'http://www.bayre.com/add_score.php?Userid=123456&Name=Sibly&Score=90000' (multiplatform)

after this i can use php and mysql to retreive the score table or add something !

Thanks !


xlsior(Posted 2010) [#9]
Yes, you can -- that's actually really easy to do from within Blitzmax.
Any of the read commands that work with streams can load data straight over HTTP.
Here's a sample:

file=OpenFile("http::www.bayre.com/add_score.php?USerid=123456&Name=Sibly&score=90000")

If Not file RuntimeError "Error""

While Not Eof(file)
Print ReadLine(file)
Wend
CloseStream file


Note that the URL starts with http:: instead of the 'typical' http://, since http:: is the indicator blitzmax uses to refer to http streams.

Keep in mind that anyone who has a firewall can see the full URL you're passing in their logs. They can then trivially easily submit the same URL manually with a super-inflated highscore -- so I would recommend you either encrypt the info you're submitting (and have the php page decrypt & validate the info), or use some other way to verify that it's legit.


xlsior(Posted 2010) [#10]
Note: if you do use the above to submit scores to your server, you can have the PHP page in question *output* the actual highscore table at the same time it submits the users own info, so the readline commands in the above sample will retrieve the current highscores...


hub(Posted 2010) [#11]
i don't know too how to manage a easy online score table. What could be the best and easy method. Just associate an unique id to the player (ie generate an random number to it).

Function Creer_nombre_aleatoire:Int (Longueur : Int)

	Local Chaine$
	Local i
	Local Nombre
	
	Chaine$ = ""
	For i = 0 To Longueur-1
		Chaine$ = Chaine$ + String(Rand(9))
	Next
	Nombre = Int (Chaine$)

	Return Nombre

End Function


or something else. (generate an unique id for each game downloaded)
no idea this evening for this. Just want that the player could play with its 'name' if the game is lauched from another computer or if downlod it again after desintall it. Or perhaps generate a unique serial-code from its email adress ?


Volker(Posted 2010) [#12]
There is some code in the archiv:
http://www.blitzbasic.com/codearcs/codearcs.php?code=992

Creating a key out of a name, mailadresse or any other string.