|
| 23 Dec 2013 06:53 PM |
| How can I use PHP to retrieve and process what the ROBLOX server sends via PostAsync() |
|
|
| Report Abuse |
|
|
Kenetec
|
  |
| Joined: 26 Nov 2009 |
| Total Posts: 1662 |
|
|
| 23 Dec 2013 07:03 PM |
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 |
|
|
| Report Abuse |
|
|
|
| 23 Dec 2013 07:12 PM |
| Thanks, I thought it would be unique. |
|
|
| Report Abuse |
|
|
|
| 23 Dec 2013 07:29 PM |
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? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 23 Dec 2013 08:57 PM |
| no, you did it pretty wrong. |
|
|
| Report Abuse |
|
|
| |
|
|
| 23 Dec 2013 10:31 PM |
| what did I do wrong though, is the thing. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 23 Dec 2013 10:32 PM |
the PHP is completely wrong and so is this: PostAsync (url, "$rbxVar='lel roblux'", application/x-www-form-urlencoded) |
|
|
| Report Abuse |
|
|
| |
|
Seranok
|
  |
| Joined: 12 Dec 2009 |
| Total Posts: 11083 |
|
|
| 23 Dec 2013 11:05 PM |
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']; |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 23 Dec 2013 11:08 PM |
| He forgot the " < " in ?php and the " > " to close it |
|
|
| Report Abuse |
|
|
Seranok
|
  |
| Joined: 12 Dec 2009 |
| Total Posts: 11083 |
|
|
| 23 Dec 2013 11:11 PM |
| I intentionally omitted the tags because I thought the filter might reject my post if I included them. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
|
| 24 Dec 2013 07:27 AM |
| HTTP tutorial pls someone and u have my <3 forevar |
|
|
| Report Abuse |
|
|
|
| 24 Dec 2013 07:47 AM |
How exactly am I supposed to translate lua into php when encoding it? local body = "rbxVar=" .. httpService:UrlEncode("lel roblux") |
|
|
| Report Abuse |
|
|
|
| 24 Dec 2013 08:06 AM |
| I'm new to back-end web development, I usually make otherwise. |
|
|
| Report Abuse |
|
|
MettaurSp
|
  |
| Joined: 20 Mar 2010 |
| Total Posts: 3179 |
|
|
| 24 Dec 2013 09:45 AM |
| I just learned GET so I wouldn't have to learn anything else when making the PHP file. |
|
|
| Report Abuse |
|
|
|
| 24 Dec 2013 03:05 PM |
| 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 = '. |
|
|
| Report Abuse |
|
|
Seranok
|
  |
| Joined: 12 Dec 2009 |
| Total Posts: 11083 |
|
|
| 24 Dec 2013 04:32 PM |
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) |
|
|
| Report Abuse |
|
|
|
| 24 Dec 2013 05:11 PM |
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); |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
Seranok
|
  |
| Joined: 12 Dec 2009 |
| Total Posts: 11083 |
|
|
| 24 Dec 2013 09:13 PM |
instead of: char.GetPlayerFromCharacter() do: Game.Players:GetPlayerFromCharacter(char)
and instead of: url_encode({ userID, username }); do url_encode({ userId = userID, username = username }); |
|
|
| Report Abuse |
|
|
jackendra
|
  |
| Joined: 20 Mar 2011 |
| Total Posts: 66 |
|
|
| 07 Feb 2014 02:13 PM |
I still cant get it too work.
I tried tons of Lua code and PHP code.
Maybe its my web host?
|
|
|
| Report Abuse |
|
|
jackendra
|
  |
| Joined: 20 Mar 2011 |
| Total Posts: 66 |
|
|
| 07 Feb 2014 02:16 PM |
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 |
|
|
| Report Abuse |
|
|
Kenetec
|
  |
| Joined: 26 Nov 2009 |
| Total Posts: 1662 |
|
|
| 07 Feb 2014 02:21 PM |
| You're using getasync, not postasync |
|
|
| Report Abuse |
|
|