Using HTTP to gather a variable in php to process in lua
#1
Posted 09 July 2017 - 12:14 AM
#2
Posted 09 July 2017 - 12:36 AM
local h = http.get( "your link here" ) print( h.readAll() ) h.close()
PHP:
echo "Hello World";
#3
Posted 09 July 2017 - 01:17 AM
KingofGamesYami, on 09 July 2017 - 12:36 AM, said:
local h = http.get( "your link here" ) print( h.readAll() ) h.close()
PHP:
echo "Hello World";
No such as if i had a variable named updatedVersion and currentVersion. Then i say if currentVersion is less than updatedVersion it does so and so. How do i do that?
#4
Posted 09 July 2017 - 01:56 AM
local h = http.get( "your link here" ) print( h.readAll() == "1.0" ) h.close()
PHP:
echo "1.1";
#5
Posted 09 July 2017 - 02:01 AM
KingofGamesYami, on 09 July 2017 - 01:56 AM, said:
local h = http.get( "your link here" ) print( h.readAll() == "1.0" ) h.close()
PHP:
echo "1.1";
EDIT: This code does not work. All it says is False all the time when I test this and I have no clue on where i can insert code to where a pastebin can run when there is a update.
Edited by Weareverylucky, 09 July 2017 - 05:48 PM.
#6
Posted 09 July 2017 - 06:58 PM
#7
Posted 09 July 2017 - 11:10 PM
(Note: Even in that case, you could remove all of the '.' in lua; though this would mean you'd have to keep the format consistent. Ie, you couldn't move from 1.0 to 1.0.1 or 1.0.0 to 1.0.01 without potentially causing issues. (like from going from 1.0.11 from 1.0.2, you'd have to put 1.0.20 as it'd be comparing 1011 to 102)
I've set up these two samples to hopefully demonstrate this & help your understanding:
First webpage
https://cc.tylertwin...var/1point0.php
<?php
header("Content-Type: text/plain");
echo "1.0";
?>
Second webpage
https://cc.tylertwin...var/1point1.php
<?php
header("Content-Type: text/plain");
echo "1.1";
?>
Lua:
pastebin run 1VZga5iN
This will check both versions and tell if they're up to date with the default version (1.0). You can additionally run `pastebin run 1VZga5iN 1.1` and you'll see the issue that the 1.0 webpage will return false, as if it's out of date when the client would technically be ahead.
The "Content-Type" headers are not very necessary. It's more used to make it more viewable in a webpage (and technically more correct), because it sees it as a text document instead of an HTML page.
Edited by Twijn, 09 July 2017 - 11:17 PM.
#8
Posted 17 July 2017 - 03:21 AM
Lua
local protocol, domain, port, file, query = 'http://', 'localhost', ':80/', 'lua-request.php?', 'version=1.0' local handle = http.get(protocol .. domain .. port .. file .. query); local txt = handle.readAll(); handle.close(); print(txt);
PHP File
<?php $versions = [ '1.0' => 'Version 1.0 is an old version', '1.1' => 'Version 1.1 is a new version' ]; echo $versions[$_GET['version']];
Output
Version 1.0 is an old version!
#9
Posted 07 August 2017 - 05:01 AM
Twijn, on 09 July 2017 - 11:10 PM, said:
(Note: Even in that case, you could remove all of the '.' in lua; though this would mean you'd have to keep the format consistent. Ie, you couldn't move from 1.0 to 1.0.1 or 1.0.0 to 1.0.01 without potentially causing issues. (like from going from 1.0.11 from 1.0.2, you'd have to put 1.0.20 as it'd be comparing 1011 to 102)
I've set up these two samples to hopefully demonstrate this & help your understanding:
First webpage
https://cc.tylertwin...var/1point0.php
<?php
header("Content-Type: text/plain");
echo "1.0";
?>
Second webpage
https://cc.tylertwin...var/1point1.php
<?php
header("Content-Type: text/plain");
echo "1.1";
?>
Lua:
pastebin run 1VZga5iN
This will check both versions and tell if they're up to date with the default version (1.0). You can additionally run `pastebin run 1VZga5iN 1.1` and you'll see the issue that the 1.0 webpage will return false, as if it's out of date when the client would technically be ahead.
The "Content-Type" headers are not very necessary. It's more used to make it more viewable in a webpage (and technically more correct), because it sees it as a text document instead of an HTML page.
Edited by Weareverylucky, 07 August 2017 - 05:02 AM.
#10
Posted 07 August 2017 - 10:27 AM
#11
Posted 07 August 2017 - 06:53 PM
Twijn, on 09 July 2017 - 11:10 PM, said:
(Note: Even in that case, you could remove all of the '.' in lua; though this would mean you'd have to keep the format consistent. Ie, you couldn't move from 1.0 to 1.0.1 or 1.0.0 to 1.0.01 without potentially causing issues. (like from going from 1.0.11 from 1.0.2, you'd have to put 1.0.20 as it'd be comparing 1011 to 102)
I've set up these two samples to hopefully demonstrate this & help your understanding:
First webpage
https://cc.tylertwin...var/1point0.php
<?php
header("Content-Type: text/plain");
echo "1.0";
?>
Second webpage
https://cc.tylertwin...var/1point1.php
<?php
header("Content-Type: text/plain");
echo "1.1";
?>
Lua:
pastebin run 1VZga5iN
This will check both versions and tell if they're up to date with the default version (1.0). You can additionally run `pastebin run 1VZga5iN 1.1` and you'll see the issue that the 1.0 webpage will return false, as if it's out of date when the client would technically be ahead.
The "Content-Type" headers are not very necessary. It's more used to make it more viewable in a webpage (and technically more correct), because it sees it as a text document instead of an HTML page.
Alternatively, you can use string.gmatch and compare each version number individually. This works with strings like "1.0.1".
function isOutdated(current, remote)
local cfunc = current:gmatch("%d+")
local rfunc = remote:gmatch("%d+")
local cnum = tonumber(cfunc())
local rnum = tonumber(rfunc())
while cnum and rnum do
if cnum ~= rnum then
return cnum < rnum
end
cnum = tonumber(cfunc())
rnum = tonumber(rfunc())
end
return rnum ~= nil
end
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











