I have a JS game (on a HTML page) and I want to create a log file every time someone plays, so that I can record thing like their score, and the amount of time they played.
I know that JS is a client side language, so how can I go about saving a file to a server? Is it possible to insert some .php in my JS to accomplish such a thing? Or is there a better way?
Thanks!
In order to send data to the server, you must make an HTTP request. (Making an HTTP request from JavaScript without leaving the page is known as Ajax). For this type of situation, this is usually done using the XMLHttpRequest object. You then need a server side program (which you could write in PHP) to process the request and save the data. To avoid having to worry about file locking and the like, you should consider using a database instead of a flat file.