File: cookie.ecpp

package info (click to toggle)
tntnet 3.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,488 kB
  • sloc: cpp: 16,636; javascript: 8,109; ansic: 2,189; makefile: 861; sh: 317; xml: 258; perl: 159; sql: 14
file content (46 lines) | stat: -rw-r--r-- 982 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<#
  This is a simple hello-world-application with cookie-support

  It stores the name in a cookie
#>
<%args>
name;            // define query-parameter
                 // this defines a variable of type std::string with
                 // the name "name"
bool clearcookie;
</%args>
<%cpp>

  if (name.empty())
    name = request.getCookie("name");

  if (clearcookie)
  {
    reply.clearCookie("name");   // delete cookie from client
  }
  else if (!name.empty() && request.getCookie("name").getValue() != name)
  {
    reply.setCookie("name", name, 3600);  // set cookie when new or modified
  }

</%cpp>
<html>
 <head>
  <title>Hello World-application for tntnet</title>
 </head>

 <body>

  <h1>Hello <$ name.empty() ? "World" : name $></h1>

  <form>
   What's your name?
   <input type="text" name="name" value="<$name$>"> <br>
   <input type="submit">
   <input type="submit" name="clearcookie" value="delete cookie">
  </form>

  <a href='.'>reload</a>

 </body>
</html>