• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by pancyp · Aug 29, 2018 at 09:37 AM · webglsave dataphphtmlwrite data

send data from embedded game through PHP?

Hi, I'm looking to upload and embed my game to an online website, and have found an online host simmer.io to upload my game. However I want to send the game data through a PHP script to write the game data to a local file.

I followed this tutorial from Holistic3D on reading and writing to a text file from unity webGL (https://www.youtube.com/watch?v=4OZqY1Ukj8I) and got this piece of code that supposedly talks to the PHP server.

     public void saveScores()
     {
         StartCoroutine(sendTextToFile());
         SceneManager.LoadScene("Close prompt");
     }
 
 
 
     IEnumerator sendTextToFile()
     { bool successful = true;
         WWWForm form = new WWWForm();
         form.AddField("Name", participantID);
         form.AddField("MC_attempts", MC_attempts);
         form.AddField("MC_time_taken", MC_time);
         form.AddField("Ped_attempts", Ped_attempts);
         form.AddField("Ped_time_taken", Ped_time);
         form.AddField("Level_order", levelOrder);
         WWW www = new WWW("https://simmer.io/@Pancy/Pelmanism/sendfromunity.php", form);   //line51
 
         yield return www;
         if (www.error != null)
         {
             successful = false;
         }
         else
         {
             Debug.Log(www.text);
             successful = true;
         }
     }

and then I've got this PHP code that should write the data to a text file:

 <?php
 
     $Name =$_POST["Name"];
     $MC_attempts = $_POST["MC_attempts"];
     $MC_time = $_POST["MC_time_taken"];
     $Ped_attempts = $_POST["Ped_attempts"];
     $Ped_time = $_POST["Ped_time_taken"];
     $levelOrder = $_POST["Level_order"];
 
 
 
     if ($Name != "")
     {
         echo("Message successfully sent");
         echo("Field 1: " . $Name);
         echo("Field 6: " . $levelOrder);
         $file = fopen("webgl_data.txt", "a");
         fwrite($file, $Name." ".$MC_attempts." ".$MC_time." ".$Ped_attempts." ".$Ped_time." ".$levelOrder."\r\n");
         fclose($file);
     }
     else
     {
         echo("Message delivery failed");
     }
 ?>

It works when I'm replacing the webform as http://localhost:8012/sendfromunity.php in line 51, but after uploading my game the local host url doesn't work. I've tried changing it to the url of my game but it still couldn't work.

I'm aware I might have made some silly mistakes or might have even misunderstood the entire tutorial; so if anyone could point me in the right direction I would be eternally grateful!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

92 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

VideoPlayer not playing in WebGL Build 0 Answers

Can i use HTML and PHP pages to be displayed in Unity project ? 1 Answer

WebGL - find out vieport size (x,y) 0 Answers

How to make a high score file for webGL? 1 Answer

DataContractJsonSerializer in WebGL 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges