Jump to content
  • 0

API website Problem


HappySV

Question

Hello, at the exit Multiplayer and with the help of an admin we have devised an API to display the status of the servers from my site.

Today that has changed site I decided to recreate the page but I have a problem.

I actually managed to get the "index.php and TruckMPApi.php" file but it still does not work as you can see this address.

http://status.cobra-gaming.eu/

I suspect that something is missing for reading server information but I do not know where to look.

I attached to this post a link to the files winrar "index and TruckMPApi"


cordially

Sorry for my English but I'm French and google translation is not too developed.

Edited by FirestarteR93
Removed the link to the archive due to security reasons
Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 0

You don't need to use TruckMPApi, coz' it is excessive for your situation.

 

Try this (just an example):

<?php    $servers = json_decode(@file_get_contents("http://api.ets2mp.com/servers/"), true);    var_export($servers["response"]);?>

`true` in the first line says, that you want to use $servers as array, not as object. If you don't know, khow to use arrays, taking a look at this help: http://php.net/manual/en/language.types.array.php

 

So, you can use this array smth like that (as an example, of course):

foreach ($servers["response"] as $key => $server) {    echo '<p>'.$server["name"].' - '.$server["players"].'/'.$server["maxplayers"].'</p>';}
Edited by CJMAXiK
  • Upvote 2
Link to comment
Share on other sites

  • 0
  • Web Developer

Also the way you're doing it will cause you to get ban from the API. Because each time someone visit your page. It will send a request to the API and if there's too many request to the API for unknown reason, it will cause your IP to be banned. 

Also WebSocket is way too overkill to do it. You can do it easily with 10 lines of code~

 

Link to comment
Share on other sites

  • 0

So I prefer abandoned, I will not be banned from servers ETS2 why ...

Too bad I could try ..

And the WebSocket, I'm really new at this matter that's why I'm asking for help ..

Anyway thank you for helping me in my first approach.

Cordially.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.