xeon17 Posted July 5, 2016 Share Posted July 5, 2016 This is this always returning false? fetchRemote("http://mta.balkan-gaming.co/location.php", function(responseData, errno) if errno == 0 then setElementData(localPlayer, "language",responseData) end outputChatBox(errno.." - ".. tostring(responseData)) end) language.php <?php include("mta_sdk.php"); mta::doReturn(substr($_SERVER["HTTP_ACCEPT_LANGUAGE"],0,2)); ?> Link to comment
Discord Moderators AlexTMjugador Posted July 5, 2016 Discord Moderators Share Posted July 5, 2016 fetchRemote can't be used clientside with webpages hosted in any server but the server the client is connected to. If your domain name resolves to the MTA: SA server IP and HTTP port used by MTA: SA and it still doesn't work, try using the IP and port directly instead. Link to comment
xeon17 Posted July 7, 2016 Author Share Posted July 7, 2016 I tried it on my local server, and i have the same problem. I'm using appserv. localhost and 127.0.0.1 are returning 1006 while my internal IP is returning false. Which port should i use? server http port or appserv? sorry, first time using fetchRemote. Link to comment
Discord Moderators AlexTMjugador Posted July 7, 2016 Discord Moderators Share Posted July 7, 2016 You should use the server HTTP port with fetchRemote. Link to comment
xeon17 Posted July 7, 2016 Author Share Posted July 7, 2016 With port , it returns 0 - This is the page you want Without port it returns, 0- false Link to comment
Discord Moderators AlexTMjugador Posted July 7, 2016 Discord Moderators Share Posted July 7, 2016 In order to fetchRemote to return something more useful from your server, you should access a certain file within a certain resource. For example, to read index.htm from the resource web: http://IP:PORT/web/index.htm. To know how you can publish a resource or file to the web interface, you can read this wiki article and/or see how some default resources have used the web interface (for example, performancebrowser). Link to comment
xeon17 Posted July 9, 2016 Author Share Posted July 9, 2016 <php src="mta_sdk.php" /> <php src="location.php" /> Doesn't seems to work. Cannot find a resource file named 'location.php' in the resource Language. Link to comment
Discord Moderators AlexTMjugador Posted July 9, 2016 Discord Moderators Share Posted July 9, 2016 That doesn't work because I admit I confused you a bit. Continue reading and you'll know why Firstly, the built-in HTTP server is just a HTML server. It is not able to process PHP scripts, although Lua code can be embedded within HTML pages to provide dynamic output, in a somewhat similar fashion to PHP. Therefore your PHP pages won't work even if you manage to add them by using the tag in the meta.xml file.As you may have thought, the most convenient thing to do for exporting web functions to your scripts is using HTML with inlined script, so that you don't need to set up external webservers and everything gets easier to manage. However, that's not possible in your case, because you need PHP in order to get players' location. So the real question is: can we do something to circumvent this shortcoming? It seems impossible to get the result of that script if fetchRemote isn't able to do anything outside the server's HTTP interface, right? Not quite. And here's where things get interesting: do you remember that your script is clientside? The clientside fetchRemote is limited, but the serverside version is not: with the serverside version you can fetch the result of any webpage in any server and port. That means that you can host a different server, even if it's on the same machine, and get the result of it by only using fetchRemote in the server. Therefore, we can now reformulate the previous question: what we can do to get the result of that serverside fetchRemote in a client? Well, providing that you are already using element data, you only need to call the function serverside and set the element data there, and make sure that the client knows how to deal with that element data change accordingly. You can use the onClientElementDataChange event for that, if you want or need to. If you want to script your own data transfer approach, which can be more efficient in terms of bandwidth, use triggerClientEvent and you are set. Link to comment
xeon17 Posted July 9, 2016 Author Share Posted July 9, 2016 Even on server side it returns false. Tried localhost and internal ip too. function onResourceStart() for _, player in ipairs(getElementsByType("player")) do local fetch = fetchRemote("http://127.0.0.1:80/location.php", function (responseData, errno) if (errno) == 0 then setElementData(player, "language",tostring(responseData)) outputChatBox(tostring(fetch)) -- returns nil outputChatBox(getPlayerName(player)..": "..errno.." - ".. tostring(responseData)) -- returns xeon17: 0 - [false] end end) end end addEventHandler("onResourceStart", resourceRoot, onResourceStart) Link to comment
Discord Moderators AlexTMjugador Posted July 10, 2016 Discord Moderators Share Posted July 10, 2016 It looks like your PHP page doesn't return useful data to fetch. Have you tried using callRemote? It submits a different request to the server, so you can expect it to return different results. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now