Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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.

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

Make a Register/Login page using html and then use it to log into a Unity Game,Hi! 1 Answer

How create customize bg on facebook, unity WebGl? 0 Answers

Itch.io webgl not uploading properly 1 Answer

Webgl browser error " DirectoryNotFoundException: Could not find a part of the path" 0 Answers

Embedded HTML for Unity WebGL build 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges