Question

What's Lua's equivalent to php's $_GET for a web application?

Also if the url is something like index.cgi?thisisatest how can I get everything after the question mark?

Was it helpful?

Solution

In the context of lighttpd and mod_magnet, query strings are not parsed automatically so you need to do it yourself. You can find an example here, look for "flv-streaming.lua" in the page.

As for your second question, Lorenzo gave you a generic answer, but in mod_magnet you can also use lighty.env["uri.query"] as seen in the same example.

OTHER TIPS

Lua in itself is not a language for web development. There are some libraries for that. You can try luasocket.

As for your second question:

local url = "index.cgi?thisisatest"
local suffix = string.match( url, "^[^?]+?([^?]-)$" )
print( suffix )

If you are running your Lua code in Ophal, then you can use the functions: request_uri() and request_path()

If you're using lua as a CGI script, os.getenv("QUERY_STRING") will return everything after the question mark/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top