I’m setting up a game client that is online-based. However, I need to be able to talk to my web server. I’ve been looking at the WWW class, and so far it seems like it can only send variables. I do not intend on letting the client connect to the database directly through an in-client .dll or similiar option - that alone is another security risk.
Is there a recommended way to call PHP -functions-, not variables and pages/classes, with the WWW call? I know you can do it with jQuery AJAX, but this doesn’t feel like it’s similar.
One way I can think of is to send a variable to the php function (using form) that will be used to decide which function to be call (whether it’s the most recommended way is something I’m not sure of due to lack of experience/ knowledge). For example in your Unity code:
string url = "Your php file url";
WWWForm form = new WWWForm ();
form.AddField("functionName", "RegisterScore");
WWW www = new WWW(url, form);
yield return www;
and in the PHP file (in the server) you get the “functionName” and the call the function:
function RegisterScore(){
//your code here
}
$functionName = $_POST["functionName"];
switch ($functionName){
case "RegisterScore":
RegisterScore();
break;
}
Keep in mind this is not a complete code. Just to give some you some idea.