From server to Website
#1

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+
Reply
#2

This is not PHP help forum.

Try to learn about $_POST and $_GET variables.
Reply
#3

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

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"]);
?>
Reply
#5

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

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

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

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.
Reply
#9

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.
..
Reply
#10

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)