|
How can I use PHP to retrieve and process what the ROBLOX server sends via PostAsync() |
|
KenetecJoin Date: 2009-11-26 Post Count: 1662 |
Just like you would with any other POST variable... $_POST['var_name']
Make sure you send the urlencoded string of vars via postasync with the UrlEncode method |
|
|
Thanks, I thought it would be unique. |
|
|
So I would run the script:
local httpService = Game:GetService("HttpService");
local url = httpService:UrlEncode("MyWebUrl/roblox/index.php")
PostAsync (url, "$rbxVar='lel roblux'", application/x-www-form-urlencoded)
and the PHP:
?php
$_POST['rbxVar'];
or do I not understand? |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
no, you did it pretty wrong. |
|
|
|
what did I do wrong though, is the thing. |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
the PHP is completely wrong and so is this:
PostAsync (url, "$rbxVar='lel roblux'", application/x-www-form-urlencoded) |
|
|
SeranokJoin Date: 2009-12-12 Post Count: 11083 |
local httpService = Game:GetService("HttpService");
local url = "http://www.example.org/roblox/index.php"
local body = "rbxVar=" .. httpService:UrlEncode("lel roblux")
httpService:PostAsync(url, body, Enum.HttpContentType.ApplicationUrlEncoded)
And you basically got the PHP right, you just need to do something with the value:
echo $_POST['rbxVar']; |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
He forgot the " " to close it |
|
SeranokJoin Date: 2009-12-12 Post Count: 11083 |
I intentionally omitted the tags because I thought the filter might reject my post if I included them. |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
oh |
|
AlyteJoin Date: 2011-10-24 Post Count: 10090 |
HTTP tutorial pls someone and u have my <3 forevar |
|
|
How exactly am I supposed to translate lua into php when encoding it?
local body = "rbxVar=" .. httpService:UrlEncode("lel roblux") |
|
|
I'm new to back-end web development, I usually make otherwise. |
|
MettaurSpJoin Date: 2010-03-20 Post Count: 3179 |
I just learned GET so I wouldn't have to learn anything else when making the PHP file. |
|
|
I put in the necessary PHP for when a user steps on a block, it puts the user's ID and username into a database. I just need to know how to translate PHP to Lua for 'body = '. |
|
SeranokJoin Date: 2009-12-12 Post Count: 11083 |
Okay, so your PHP script is expecting the request body to be in this format:
key=value&key2=value2
So it's a semicolon-separated list of key-value pairs. However, you should always URL encode keys and values because they might contain characters like '&' or '=' and that might mess things up. Here is a function which will do it for you:
local HttpService = Game:GetService("HttpService")
function url_encode(form)
local result = {}
for key, value in pairs(form) do
table.insert(result, HttpService:UrlEncode(key) .. "=" .. HttpService:UrlEncode(value))
end
return table.concat(result, "&")
end
And you would use it like this:
local url = "http://www.example.org/roblox/index.php"
local body = url_encode({ userId = 261, userName = Shedletsky })
HttpService:PostAsync(url, body, Enum.HttpContentType.ApplicationUrlEncoded) |
|
|
So this script would work:
local httpService = Game:GetService("HttpService");
url = "myurl";
local block = script.Parent;
function detectBlockStep(hit)
local h = hit.Parent:findFirstChild("Humanoid");
if h ~= nil then
char = h.Parent;
username = char.Name
userID = char.GetPlayerFromCharacter().userId
local body = url_encode({ userID, username });
end
end
block.Touched:connect(detectBlockStep);
with:
$con=mysqli_connect("myurl","dbuser","dbuserpass","dbname");
$userID = $_POST['userID'];
$username = $_POST['username'];
mysqli_query($con,"INSERT INTO rbxBrick (userID, username) VALUES ($userID, $username)");
mysqli_close($con); |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
Guise injecting time |
|
SeranokJoin Date: 2009-12-12 Post Count: 11083 |
instead of:
char.GetPlayerFromCharacter()
do:
Game.Players:GetPlayerFromCharacter(char)
and instead of:
url_encode({ userID, username });
do
url_encode({ userId = userID, username = username }); |
|
jackendraJoin Date: 2011-03-20 Post Count: 66 |
I still cant get it too work.
I tried tons of Lua code and PHP code.
Maybe its my web host?
|
|
jackendraJoin Date: 2011-03-20 Post Count: 66 |
Php:
$fp = fopen('data.txt', 'w');
fwrite($fp, $_POST['var']);
fwrite($fp, $_GET['var']);
fclose($fp);
Lua:
local httpService = Game:GetService("HttpService");
url = "http://roscript.site88.net/http.php";
local body = "var=" .. httpService:UrlEncode("roblox");
httpService:GetAsync(url, body, Enum.HttpContentType.TextPlain); -- Also tried Enum.HttpContentType.ApplicationUrlEncoded |
|
KenetecJoin Date: 2009-11-26 Post Count: 1662 |
You're using getasync, not postasync |
|