SA-MP Forums Archive
From server to Website - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: From server to Website (/showthread.php?tid=492475)



From server to Website - Jacapo - 04.02.2014

Hello everyone. I trying how to make function that sends data to a website(.php).

My work(Gamemode):
pawn Код:
public OnPlayerConnect(playerid)
{
    HTTP(playerid, HTTP_POST, "twor.wz.sk/pripojenia.php", "", "SendJoinMessage");
    return 1;
}

forward SendJoinMessage(index, response_code, data[]);
public SendJoinMessage(index, response_code, data[])
{
    if(response_code == 200)
    {
        //What to do here
    }
    else print("Failed");
}
Website:
PHP код:
<?php
    print_r
("Player $_POST has joined the server.");
?>
I am really new to PHP. Help me if you know the solution. REP+


Re: From server to Website - Borg - 04.02.2014

This is not PHP help forum.

Try to learn about $_POST and $_GET variables.


Re: From server to Website - Jacapo - 04.02.2014

Yes this is not PHP forum, but its connected to pawn(sa-mp server).


Re: From server to Website - Borg - 04.02.2014

Only the mistake connected to samp is that you do not send POST parameters in HTTP function, but you are using POST method and try to read POST variable in .php script.

The easier way for is to use $_GET variables.

pawn Код:
public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME+1], query_string[128];
    GetPlayerName(playerid, name, sizeof(name));
    format(query_string, sizeof(query_string), "twor.wz.sk/pripojenia.php?playername=%s", name);
    HTTP(playerid, HTTP_GET, query_string, "", "SendJoinMessage");
    return 1;
}

forward SendJoinMessage(index, response_code, data[]);
public SendJoinMessage(index, response_code, data[])
{
    if(response_code == 200)
    {
        //PHP script executed successful.
        SendClientMessageToAll(-1, data); //will print "Hi, %playername%" to all players
    }
    else print("Failed");
}
PHP код:
<?php 
    printf
("Hi, %s!"$_GET["playername"]);
?>



Re: From server to Website - Jacapo - 04.02.2014

It works well, but only in gamemode. In php will print only: "Hi, !" - playername is blank idk whats wrong.
In gamemode print: "Hi, Player!".


Re: From server to Website - Borg - 04.02.2014

Because you do not send playername parameter. Try this link in your browser
twor.wz.sk/pripojenia.php?playername=Jacapo


Re: From server to Website - Jacapo - 04.02.2014

Oh i see, but is possible to show who is connect without "?playername=somenick" ?


Re: From server to Website - Borg - 04.02.2014

Where do you want to see who is connecting? This is one-time script execution. in ?playername=somenick it send the player's name to your php script. And you can do whatever you want with the name in your script. You have to learn more about PHP.

EDIT: basically, the code I sent sends the player's name when he connects to your php script. PHP script writes string "Hi, + playername + !", and sends it to your gamemode. And then your gamemode displays the received string.


Re: From server to Website - Jacapo - 04.02.2014

I just want to create this: When user click on my website link (Server) -> Example:

Player nick1 joined the server.
Player nick2 joined the server.
Player nick3 joined the server.
..


Re: From server to Website - Borg - 04.02.2014

so you have to save the names somewhere like in a database or in a file. and then load them from the file or the database when somebody loads your webpage