of     2   
chevron_rightchevron_rightchevron_right

Digitalizing
#121000456Tuesday, December 24, 2013 12:53 AM GMT

How can I use PHP to retrieve and process what the ROBLOX server sends via PostAsync()
Kenetec
#121001335Tuesday, December 24, 2013 1:03 AM GMT

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
Digitalizing
#121002180Tuesday, December 24, 2013 1:12 AM GMT

Thanks, I thought it would be unique.
Digitalizing
#121003829Tuesday, December 24, 2013 1:29 AM GMT

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?
cntkillme
#121013050Tuesday, December 24, 2013 2:57 AM GMT

no, you did it pretty wrong.
Digitalizing
#121014327Tuesday, December 24, 2013 3:09 AM GMT

expected that.
Digitalizing
#121022022Tuesday, December 24, 2013 4:31 AM GMT

what did I do wrong though, is the thing.
cntkillme
#121022160Tuesday, December 24, 2013 4:32 AM GMT

the PHP is completely wrong and so is this: PostAsync (url, "$rbxVar='lel roblux'", application/x-www-form-urlencoded)
Digitalizing
#121023917Tuesday, December 24, 2013 4:50 AM GMT

well *what* is wrong
Seranok
#121025402Tuesday, December 24, 2013 5:05 AM GMT

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'];
cntkillme
#121025705Tuesday, December 24, 2013 5:08 AM GMT

He forgot the " " to close it
Seranok
#121025937Tuesday, December 24, 2013 5:11 AM GMT

I intentionally omitted the tags because I thought the filter might reject my post if I included them.
cntkillme
#121026102Tuesday, December 24, 2013 5:12 AM GMT

oh
Alyte
#121046346Tuesday, December 24, 2013 1:27 PM GMT

HTTP tutorial pls someone and u have my <3 forevar
Digitalizing
#121047102Tuesday, December 24, 2013 1:47 PM GMT

How exactly am I supposed to translate lua into php when encoding it? local body = "rbxVar=" .. httpService:UrlEncode("lel roblux")
Digitalizing
#121047954Tuesday, December 24, 2013 2:06 PM GMT

I'm new to back-end web development, I usually make otherwise.
MettaurSp
#121054708Tuesday, December 24, 2013 3:45 PM GMT

I just learned GET so I wouldn't have to learn anything else when making the PHP file.
Digitalizing
#121084944Tuesday, December 24, 2013 9:05 PM GMT

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 = '.
Seranok
#121093071Tuesday, December 24, 2013 10:32 PM GMT

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)
Digitalizing
#121096729Tuesday, December 24, 2013 11:11 PM GMT

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);
cntkillme
#121105322Wednesday, December 25, 2013 12:48 AM GMT

Guise injecting time
Seranok
#121117145Wednesday, December 25, 2013 3:13 AM GMT

instead of: char.GetPlayerFromCharacter() do: Game.Players:GetPlayerFromCharacter(char) and instead of: url_encode({ userID, username }); do url_encode({ userId = userID, username = username });
jackendra
#125089747Friday, February 07, 2014 8:13 PM GMT

I still cant get it too work. I tried tons of Lua code and PHP code. Maybe its my web host?
jackendra
#125089898Friday, February 07, 2014 8:16 PM GMT

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
Kenetec
#125090269Friday, February 07, 2014 8:21 PM GMT

You're using getasync, not postasync

    of     2   
chevron_rightchevron_rightchevron_right