lighttpd lua query string access

Forum: Programming and Scripting
Topic: lighttpd lua query string access
started by: humpty

Posted by humpty on April 01 2008,16:20
anyone familiar with lighttpd using lua scripts ?

i'm trying to call a lua script by supplying a query string in a link ;

<a href="goto_date.lua?31-3-2008">1</a>

but don't know how to get to the query string argument(s)

arg[0] only holds the program path
arg[1] is nil

how do i get the date ?  ???

Posted by lucky13 on April 01 2008,16:43
Not sure I understand if this is based on user input or parsing some date variable. Try this yet?
< >

Posted by mikshaw on April 01 2008,16:51
It's an environment variable

Try os.getenv("QUERY_STRING")

Here's an example I have in one of my in-progress cgi scripts
Code Sample
-- break up query string
params=" "..string.gsub(os.getenv("QUERY_STRING"),"&"," ").." "

function get_param(var)
local p=string.gsub(params,".*"..var.."=(.-)%s.*","%1")
-- strip any naughty leading path


This particular function breaks up a string that uses the format
The lua script would end up setting var_a="something" and var_b="somethingelse"

Posted by humpty on April 02 2008,01:42
tks mikshaw, that's just what i was looking for.
Posted by roberts on April 03 2008,19:51
mikshaw wrote:
Here's an example I have in one of my in-progress cgi scripts

Just curious, did the existing cgi.lua not work for you?

We have had cgi.lua together with sample lua scripts for monkey webserver since before murgaLua.

Posted by mikshaw on April 04 2008,01:22
Just curious, did the existing cgi.lua not work for you?
Honestly I never thought to try it.  Now that you mention it I remember seeing it before, but that was before considering using Lua as CGI.  And what I've done so far has been few-and-far-between tests on a local-network-only website, so I haven't been too serious about exploring it.

I'll be sure to look into cgi.lua now.

While murgaLua is a great tool for making quick and small interfaces, i wonder if it might be a little heavy for use on a web server. I just installed Lua a few days ago in an attempt to compile some modules for murgaLua, but I'm wondering if it might also be useful as a mydsl extension. So far I haven't succeeded in compiling any binary Lua modules, though, so I've moved toward looking at modules written in Lua.  As a result, and a side note, I finally understand the use of  ...  as a function parameter, and expect it will be quite useful in future scripts.  As a result of that result, I'm guessing the underscore has some very useful usefulness that I have yet to understand.

Posted by roberts on April 04 2008,01:37
I agree. I found Lua useful before there was any fltk bindings. The first Lua in DSL was plain Lua.
I also have and use Lua for DOS and use the ANSI functions to print formatted screens.  :D
I think I placed Lua DOS in the dsl utils diskette.

This is the reason some, including me, wish John Murga would consider doing his excellent bindings as a module to plain Lua.
Then we would not have the extra baggage when using non gui scripts.

It may come a time when I will have to have both regular Lua and murgaLua for speed reasons.
I wish not to have to do that. This is in no way a knock on murgaLua. Each release is amazing with new capabilities resulting in even nicer looking GUIs.

Powered by Ikonboard 3.1.2a
Ikonboard © 2001 Jarvis Entertainment Group, Inc.