Is LUA is compactable to replace the PHP

25 views
Skip to first unread message

Vinu Prasad

unread,
Oct 24, 2017, 12:23:36 AM10/24/17
to Lua BR
Am using PHP as my server side scripting language. I want to change it to mod_lua scripting language. In my PHP script I used like ..

<?php
$result=$_GET['value']; // value contains a String
$fp = fopen('file.txt', 'w');
fwrite($fp,$result);
fclose($fp);
?>

A string value is simply stored into a file with PHP . Is these program can be converted into mod_lua ?? I don't know how to make it possible in mod_lua ? please help ..

Denis Dos Santos Silva

unread,
Oct 24, 2017, 2:07:42 PM10/24/17
to Lua BR
Vinu please checkout official docs at https://httpd.apache.org/docs/trunk/mod/mod_lua.html

---
--- file.lua
---
require "string"

function handle(r)

r.content_type = "text/plain"

if r.method == 'GET' then
  get = r:parseargs();
  result = get['value'];

  o, e = pcall( function() 
   fp = io.open('file.txt', 'w');
   fp:write( result );
   fp:flush();
   fp:close();
 );

if (not o) then r:puts("fail:" . e); return false; end

r:puts("OK!");

else
  r:puts("Unsupported HTTP method " .. r.method)
end

end

--- EOF

Vinu Prasad

unread,
Nov 15, 2017, 3:17:28 AM11/15/17
to lua...@googlegroups.com
Sorry for the late replay. thanks @Denis

when I used this code , it shows internal server error, can't display anything.

--
Você recebeu essa mensagem porque está inscrito em um tópico no grupo "Lua BR" dos Grupos do Google.
Para cancelar inscrição nesse tópico, acesse https://groups.google.com/d/topic/lua-br/Y6yONfm9t5s/unsubscribe.
Para cancelar inscrição nesse grupo e todos os seus tópicos, envie um e-mail para lua-br+unsubscribe@googlegroups.com.
Acesse esse grupo em https://groups.google.com/group/lua-br.
Para mais opções, acesse https://groups.google.com/d/optout.



--
Vinu Prasad
 

Alex Silva

unread,
Nov 15, 2017, 3:28:57 AM11/15/17
to lua...@googlegroups.com
Hi Vinu,

On 15/11/17 09:17, Vinu Prasad wrote:
> Sorry for the late replay. thanks @Denis
>
> when I used this code , it shows internal server error, can't display
> anything.
>

This is the Lua mailing list for Portuguese speakers. See about the
general mailing list here: https://www.lua.org/lua-l.html

Cheers,
--
-alex
http://unendli.ch/
Reply all
Reply to author
Forward
0 new messages