PHP - Serialize to store variables on webserver

I have been working on a way to let “players” create an account with a username and password. Then they can save their progress to that account and it loads up again when they sign in later.

I’m doing this for the Unity WebPlayer format, not the standalones. When I finish this (and I think I’m getting close), I will share the method for anybody to use.

My plan is to create a javascript in the Unity game that calls a .php script on the webserver. The .php script would then collect certain variables from Unity (such as username/score/etc). Then it would serialize the variables (save them in a text file on the webserver).

My question is directed to PHP users. How does the serialize function work? I am not familiar with PHP. I have found multiple articles on the web, but they don’t use very good examples. I just can’t quite understand. So if any of the Awesome Unity People could help me out on this, it would be much appreciated.

The project I want to use this on is mythstrott.110mb.com/mythstrott.html

there is no need to serialise, you can use the WWW class and post to a php which handles the data.

Yes, but what does the .php need to have in order to handle it?

Thanks

That’s purely up to you how you store them on the server. You can use a database, or a data file on the hard drive, or whatever. My first foray years and years ago into that I was writing text files to store that information. You don’t need to serialize the data if it’s just username and password.

I have created this PHP script. Is it possible to have a javascript in Unity run this CreateAccount function in the .php file?

<?php
function CreateAccount ($id, $name, $password, $hatchets, $logs, $coins, $chopping, $pyro)
{
$accounts = "accounts.txt";
$fh = fopen($accounts, 'a') or die("can't open file");
$newAccount = $id ."+". $name ."+". $password ."+". $hatchets ."+". $logs ."+". $coins ."+". $chopping ."+". $pyro;
fwrite($fh, $newAccount);
fclose($fh);
}
?>

yes, have a look at php GET :

you can use the www clas to send your variables to the php by adding ‘?myvar1=myvartosave’ and in php you can catch those by using the GET method :
myvarreceived = _GET[‘myvar1’];

So I have the Get figured out. I’ve tested it in the web browser by manually entering the URL. How can I run the .php URL with Unity’s Javascript?

Thanks very, very much to those who have helped. If you want, I’ll test a game you made or something and give you feedback?

Answered this in your last thread, and it was answered earlier in this one:

Search unity for examples on the WWW class and you should be good to roll. :slight_smile:

Hej,

are you sharing your project or? I want to make a same thing as you for my game wher eyou first have to login with username and password but i don’t know how to save the data in sql database never worked with it before… can you guys give me a small tut or point me in the right direction?

I want to make the accounts with a php script in a webpage but you have to login with that account in a unity game. so where to start for something like that?

thanks in advance,

Lemon

Search on Google for PHP mysql, there are plenty of good tutorials on it. Once you have the php connected to the database and a user in it, you can start on the Unity part. You can use the WWW class to post and retrieve data from PHP. PHP will handle the connection to the database.