HOW GET AND POST REQUEST WORKS?

Hi a friend and i did a game, we can storage the info into a database using the POST method sending arequest to a website, but how i recover that info into gedevelop?.. i can use a GET request but how it works ? …how i GET the variables ?

You can use PHP and MySQL on the web server (server where your website lives). Send a request to PHP on your website like mywebsite.com is available for purchase - Sedo.com and PHP going to get the value from MySQL and return it to GDevelop. BUt you need to write the actual PHP code to get the value from the database and you also need to setup the database yourself…

LIzard-13 just linked a tutorial for you in your previous topic:

You may want to take some free PHP and MySQL courses first if you don’t understand it. You can find plenty on Youtube.
youtube.com/results?search_ … P+tutorial
youtube.com/results?search_ … L+tutorial

1 Like

I KNOW HE LEAVE A TUTORIAL, BUT THAT TUTORIAL SHOWS A POST REQUEST NOT A GET REQUEST, I NEED THAT TRO RETURN THE INFO TO THE GAME AGAIN

So what is your problem then?
If you know what request to send, PHP will reply with the value returned. Simple as that.
I mean, YOU need to write the PHP code to reply and return the requested value on GET request. If you don’t know how, there are many tutorials on Youtube that’s all I’m saying.

If you don’t know how to use the send request event, it pretty straight forward. Send a get request, name the content you request and then give a variable name where to store the value returned from PHP:
event.PNG

But YOU need to write the PHP code to process the request you send from GD, get the value from the database and return it to GD. It is down to you, to your web server, to PHP and MySQL to make this happen. GDevelop got absolutely nothing to do with it other than send a request and then receive the response and store the response in a variable.

ok the problem is when i request to POST info i do this according to the tutorial :

“&ginitials=”+GlobalVariableString(initials)+“&gdate=”+GlobalVariableString(date) +“&gaccuracy=”+GlobalVariableString(accuracy)+“&gscore=”+GlobalVariableString(score)

ok

Now if i request that info back o gdevelop i should use the GET request ok… but what should i write in the body of the request ? i mean should i put &initials= or what ?.. Gdevelop put the result of the request in one variable and i need to get the info of several variables.

You can actually use the POST request also to get info from the server.
The difference between the two method is only that how they handle data.
In the body, you can enter for example the value you want to request from PHP.

For example let say you have two values

$firstName = "John"; $lastName = "Doe";

You can use the body content to select, what information you want PHP to return like so:

"&return=firstName"

And then you can use the string from the body to get the value and return it

$return = $_POST['return']; echo ${$return};

In this case GDevelop should receive the response “John” because we included firstName in the body and this is what PHP return in the response.

Now if you want to return both value, the first name and the last name, you want to return it as a JSON string.

echo "{firstName: ${"firstName"}, lastName: ${"lastName"}}";

In this case, GDevelop should receive the response

{firstName: John, lastName: Doe} 

which is a JSON string and you don’t even need to use the body content if you want to return everything anyway. Just send a request to PHP and return everything from PHP in a JSON string.

And then you want to parse the JSON string in GDevelop. an example is included with GD, it called Parse JSON from API I believe. Take a look to see how to parse JSON in GDevelop.

Hope it helps :slight_smile:

Good luck.

IT DOES HELP, PLEASE IF I SEND
“&INITIALS=”+GLOBALVARIABLE(ID)

HOW I GET THE VALUE

LIKE THIS? “&RETURN=&INITIALS”

PLEASE DO IT LIKE YOU PUT IT IN GEDEVELOP, IM NEW IN PHP

You don’t need to write everything in capital letters, it is considered shouting and you have no reason to shout :slight_smile:

It is down to your PHP code, you can handle any request in any ways you want. Again if you don’t know how to write PHP you really want to sit down and take the time to learn PHP and MySQL. It is not a beginner topic really. I just give you an example how to request a specific information from PHP and how to handle that request on the PHP side. I also mentioned, if you want to return everything anyway, you don’t need to bother with the body content, just send a request to PHP with an empty body and it should return anything you tell it to return.

For example

Put the following PHP code in to a file called hello.php:

<?php echo "Hello PHP"; ?>
Put the file on your web server then send a request to the file on the web server.

host: serveraddress
page: /hello.php
variable: myVar (make sure you add the variable to the variable list in GD)
method: both POST and GET should work with this example.
body: leave it empty, not required in this example
content type: leave it empty, default

If you send a request to this file on your server it should return “Hello PHP” which GD is going to be store in myVar and you can use a text object to display it or do anything with the information. No body content required or anything fancy staff. Just a send a request from GD to hello.php and add a variable in GD to store the response. Again there is an example bundled with GDevelop called Parse JSON from API, take a look to see how to setup GDevelop.

In case you have this simple example working, all you need to do is learn some PHP to write the code that is going to return everything you want in a JSON and then you need to parse the JSON in GDevelop.

If it doesn’t work for you, you still need to learn PHP but I hope you also realize that PHP is a server side language, it runs on a server. It is not going to execute as a regular file on your computer. You can run a server on your computer for testing like WAMP or XAMPP:
wampserver.com/en/
apachefriends.org/index.html

Then you can put your php files on to this server on your computer and send a request form GD to the php file on this server.

If you want an easy way to implement requests, use ReqBin - https://reqbin.com
You can send requests right from your browser and check server performance. It’s completely free. Good luck.

Is there any plans for using a free server aligned with gdevelop directly, helping variables to exchange directly from events? :grimacing:

Dead post. See last post.