- Home /
How to get different variables from PHP page ? (example included)...
How do I create a page like this in PHP and request specific variables from that page in Unity ?
Right now I just use one text file with one variable in it and WWW request that string from the text file, convert it to an int and then use it as a variable.
Answer by Bunny83 · Oct 18, 2017 at 03:12 AM
HTTP is the Hyper Text Transfer Protocol. So by default it's ment to transmit text. However in theory you could return plain binary and encode your values any way you like. However for web services it's common to just serialize them as JSON or another text based serialization. If you really want to return your data in binary you can use the "pack" function in PHP and on the Unityside you would use a BinaryReader on the "bytes" array.
The page you showed seems to be more related to serverside storage inside a database and not that much about the format of a response.
So basically if I make that php page above , I would make it generate a 2nd page on server (http page) and then from there make the http page generate JSON data and I can call that from Unity?
Uhm, yes, basically. When you work with PHP you shouldn't see the response you are returning as a "page". You just return data. For a website this data usually is HT$$anonymous$$L. However when you want to use such a web service only for answering requests from an application you return the data in a way that can be easily read by that application.
The most common ways to return data is either using URL encoding or JSON. JSON is generally more robust and allows more complex data structures.