- Home /
How can I read a php file in localhost or remote from unity editor
Hi
I red this on lots of links, but I cant make it work for me.
What I want to do is to use this peace of code and use it to read a file on my localhost.
I use PHP in localhost. I`d like to make some sort of communication with unity, but that is not important at this point. I`d just like to make my 2 apps talks somehow from editor.
var w = WWW(url); yield w;
if (w.error != null) {
print(w.error);
} else {
print("Test ok");
formText = w.text;
print(formText);
}
I have managed to make a call only like this: I build a project, move it to my localhost (http://localhost/unity/test/WebPlayer.html), and from there make a call, and it works remotely, my online(or offline) files are updated when I make a call, but I can`t make it work from within unity3d editor.
Can that be done at all?
Thanks in advance,
this is my first post, so I might have posted it wrong, on wrong place, etc.
EDIT: When I set a default build as "standalone", I can communicate with server through unity editor.
Answer by jahroy · Sep 14, 2011 at 02:32 AM
Have you configured the WWW Security Emulation settings in the Editor?
My understanding is that the Editor will attempt to emulate the security restrictions imposed on the web player.
If you go here:
Edit -> Project Settings -> Editor
You can then specifiy the URL where your game will be hosted in the Inspector.
This will allow the Editor to simulate the security restrictions that will be imposed on your game if you publish it to that address.
This does not explain why you wouldn't be able to access a php script running on the same host as a published game.
http://unity3d.com/support/documentation/Manual/Security%20Sandbox.html
Answer by sneftel · Aug 06, 2011 at 05:46 PM
It's possible that the Unity Editor is being blocked by your computer's firewall. Check the firewall configuration to make sure there's an exception for it.
I found out later on today that when I set a default build (in unity options) to stand alone or windows build, it works, sends data to my online/offline server. It dont work when default build is set to webPlayer tho. Should it work?
any suggestions on this yet? Even my uploaded webplayer wont connect to the php in same directory. I might just be doing it wrong.. I tried url= http://address.com/scores.php, http://localhost/scores.php, just /scores.php, nothing. worked in stand alone for me too. always asks for the crossdomain.xml which doesnt work.
Your answer
Follow this Question
Related Questions
Problem reaching highscore board - crossdomain.xml issue? 1 Answer
WWW doesn't work on localhost eventhough crossdomain.xml exists 1 Answer
WWW Class is acting up 1 Answer
Is interraction between EditorWindow and php file possible? 1 Answer
How to access a PHP script on XAMPP with the use of Android device? 0 Answers