Talking to PHP broken?


#1

I try to get data from a php inside playcanvas - but the http seems to be broken!?
Any workaround on this?

With a simple ‘echo’ php:
pc.http.get(“https://www.pepworks.com/works.php ”, function (err, data) {
alert(data);
});
data is always ‘nulll’ and alert happens 2x!


#2

Look at the console for the error.

You need to set the remote server ‘pepworks.com’ to allow for cross domain access.


#3

Unfortunately it is not working, even if I launch the playcanvas project from the same server…
It took me 5 seconds in Unity to make it working and now I am trying for 4 hours to read
data from the WWW into playcanvas… I don’t think this is, how it should work (not)


#4

How are you launching from the same server? The PlayCanvas app can’t be in an iframe that has a different domain.

Are you exporting the PlayCanvas project and uploading to pepworks.com?


#5

Yes, is that still a problem?


#6

Bear in mind that you were running Unity on desktop, not from a domain so CORS doesn’t apply. If you uploaded the Unity build to a different domain to pepworks.com, then it will fail due to CORS


#7

Yes to which bit? Iframe with a different domain or exporting the project and uploading the build to pepworks.com


#8

Yes, I export the build from playcanvas and upload the full zip on pepworks.com.
Looking at the playcanvas files it should be clear to the PHP it’s on the same server!?


#9

That should work. Can you post a link to the uploaded build on pepworks.com?


#10

I’ve created a test PHP server on 000 webhost and modified the htcaccess to allow CORS.

Works fine as shown in this project: https://playcanvas.com/editor/scene/752760


#11

How did you modified the htcaccess?


#12

In my case, there was already a .htcaccess file to edit. If there isn’t one, you can create one. It’s just a text file. 000webhost had a file editor in the browser that made it easier.


#13

YEAH! Cool, have it working finally! BIG thanks, you are a rockstar, eh, yaustar :star_struck: