25.05.2014, 18:31
Send server variables to a website
gamemode:
samp.php on your website:
Example usage:
Printing the variable on a website:
gamemode:
pawn Код:
#define VARIABLEUPDATE_KEY "q4z2Y5o" //CHANGE THIS TO SOMETHING RANDOM (YOU MUST UPDATE THE KEY IN THE PHP SCRIPT TOO)
forward SendVariable(url[], varname[], value[], id);
public SendVariable(url[], varname[], value[], id)
{
new str[128];
format(str, sizeof str, "key=%s&var=%s&val=%s", VARIABLEUPDATE_KEY, varname, value);
if(HTTP(id, HTTP_POST, url, str, "HTTPResponse")) return 1;
return 0;
}
forward HTTPResponse(index, response_code, data[]);
public HTTPResponse(index, response_code, data[])
{
if(response_code == 200) if(!strcmp(data, "false")) printf("HTTP variable update failed (%s).", data);
else printf("HTTP variable update failed (%d).", response_code);
}
PHP код:
<?php
if($_POST['key'] == "q4z2Y5o") //CHANGE THIS TO SOMETHING RANDOM (YOU MUST UPDATE THE KEY IN YOUR GAMEMODE TOO)
{
file_put_contents($_POST['var'] . '.txt', $_POST['val']);
echo 'true';
}
else echo 'false';
?>
pawn Код:
public OnPlayerConnect(playerid)
{
new name[MAX_PLAYER_NAME+1];
GetPlayerName(playerid, name, sizeof(name));
SendVariable("yoursite.com (without http://) /samp.php", "LastLogged", name, playerid);
//"LastLogged" is the variable name. name is the value of the variable. playerid can be anything.
return 1;
}
PHP код:
<?php
$text = file_get_contents('LastLogged.txt');
echo $text;
?>