# How to get a value from client using uhttpd?

**URL:** <https://forum.openwrt.org/t/how-to-get-a-value-from-client-using-uhttpd/202676>\
**Category:** For Developers\
**Created:** [July 1, 2024, 2:48pm UTC](https://forum.openwrt.org/t/how-to-get-a-value-from-client-using-uhttpd/202676 "2024-07-01T14:48:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SFrancis](https://forum.openwrt.org/letter_avatar/sfrancis/32/5_5575768a8748004e209b776fc1b2916d.png) [@SFrancis](https://forum.openwrt.org/u/SFrancis)\
**Post date:** [July 1, 2024, 2:48pm UTC](https://forum.openwrt.org/t/how-to-get-a-value-from-client-using-uhttpd/202676/1 "2024-07-01T14:48:15Z")

</div>

Hello everyone!

I am beginning from scratch to learn how to make a web server using uhttpd.

I achieved to run uhttpd. It displays a static page 'index.html' located in my folder web\_server/ as I get connected to my router (IP:Port).

I would like now to be able to write data in a field of the page, and store that data in a file in the router. How can I do that?

Solutions on the web are not clear to me until now, it seems to need an additional page with lua code.

A short explanation on system 'architecture' and good practice would be a great help!

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![eduperez](https://forum.openwrt.org/user_avatar/forum.openwrt.org/eduperez/32/2066_2.png) [@eduperez](https://forum.openwrt.org/u/eduperez)\
**Post date:** [July 1, 2024, 5:31pm UTC](https://forum.openwrt.org/t/how-to-get-a-value-from-client-using-uhttpd/202676/2 "2024-07-01T17:31:09Z")

</div>

HTML pages do nothing on the server, they are just sent to the client, and the browser interprets them.

Your page needs a FORM, that sends the info to a program (not a page) on the server. That program will receive the info from the form, write the data to disk, and return a result page to the client.

---

<div class="post-metadata">

**Author:** ![SFrancis](https://forum.openwrt.org/letter_avatar/sfrancis/32/5_5575768a8748004e209b776fc1b2916d.png) [@SFrancis](https://forum.openwrt.org/u/SFrancis)\
**Post date:** [July 4, 2024, 1:11pm UTC](https://forum.openwrt.org/t/how-to-get-a-value-from-client-using-uhttpd/202676/3 "2024-07-04T13:11:49Z")

</div>

Ok, thank you!

I understand that I can add `<form action='/mypage' method='get'>` or `post` in html page to obtain data from user.

With GET, data will appear inside the url, in the HTTP request (in the HTTP body with POST).

I also understand that the parsing program to extract the data from the HTTP request is called by uhttpd, and specified in /etc/config/uhttpd config file:

```plaintext
config uhttpd main
        option listen_http '8080'
        option listen_https '4430'
        option enable_http '1'
        option enable_https '1'
        option home '/www'
        option rfc1918_filter '1'
        option max_requests '10'
        option max_connections '100'
        option cert '/etc/uhttpd.crt'
        option key '/etc/uhttpd.key'
        option cgi_prefix '/cgi-bin'
        option script_timeout '600'
        option network_timeout '30'
        option http_keepalive '0'
        option tcp_keepalive '5'
        option ubus_prefix '/ubus'
        option no_dirlists '1'
        option _httpWanAccess '0'
        option _httpsWanAccess '0'
        list lua_prefix '/api=/www/cgi-bin/api_dispatcher.lua'
        option index_page '/myserver/index.html'
        option error_page '/myserver/index.html'

```

I also understand that uhttpd calls a CGI script, that calls a more complex program (to generate page, to treat data...). Or the CGI can be complex enough to do all treatment tasks. CGI can be written in lua.

Is /www/cgi-bin/api\_dispatcher.lua this CGI complex program?

Should I specify `list lua_prefix '/api=/myserver/myprog.lua'`?

Now, I have written 2 html pages. The first one is static, and has a link (using \< href=...\>) to my second page. This second page must be able to get data from client and write them to disk.  
So CGI should react only for this second page, is it possible?

=\> I need to write a GCI script in lua called myprog.lua and set its location in uhttpd config file; myprog will parse HTTP requests and in case of data, write to disk, otherwise just print my first static page.

Isn't it?

Thank you again for your advice!

---

<div class="post-metadata">

**Author:** ![SFrancis](https://forum.openwrt.org/letter_avatar/sfrancis/32/5_5575768a8748004e209b776fc1b2916d.png) [@SFrancis](https://forum.openwrt.org/u/SFrancis)\
**Post date:** [July 10, 2024, 2:31pm UTC](https://forum.openwrt.org/t/how-to-get-a-value-from-client-using-uhttpd/202676/4 "2024-07-10T14:31:28Z")

</div>

Note: I tried to follow [this topic](https://forum.openwrt.org/t/example-of-web-interface-using-uhttpd-and-lua/67181).

No success, when I access uhttpd (IP:port), I get this page:

![image](https://forum.openwrt.org/uploads/default/original/3X/0/4/04b8d0a61749b4528c0ffbc224685b2249437248.png)

Scripts are not run.

Do you I have an advice?

Thank you in advance!
