Vely logo Empower C
install  tutorials  examples
documentation  license  about

12.1.0 released on Sep 19, 2022

Example cookies



PURPOSE:


Cookies example.

SYNTAX:


See code below.

DESCRIPTION:


Cookies example. A value is entered in the browser and saved as a cookie, then read back later.

This example is included in Vely installation. Here is how to compile and run it.

By default, Vely will automatically restart your application when a new executable is produced.

FILES:


The following are the source files for this project.

cookies.v:
// SPDX-License-Identifier: Apache-2.0
// Copyright 2018 DaSoftver LLC.


#include "vely.h"

void cookies()
{

    input-param action

    if (!strcmp (action, "enter_cookie")) {

        // Display a form to get cookie value
        out-header default
        @<h2>Enter your name</h2>
        @<form action="" method="POST">
        @    <input type="hidden" name="req" value="cookies">
        @    <input type="hidden" name="action" value="save_cookie">
        @    <label for="cookie_value">Your name:</label><br/>
        @    <input type="text" name="cookie_value" value=""><br/>
        @    <br/>
        @    <input type="submit" value="Submit">
        @</form>

    } else if (!strcmp (action, "save_cookie")) {

        // Submittal of form: save the cookie through response to the browser
        input-param cookie_value
        get-time to define cookie_expiration year 1 timezone "GMT"
        set-cookie "customer_name" = cookie_value  expires cookie_expiration  path "/"
        out-header default
        @Cookie sent to browser!
        @<hr/>

    } else if (!strcmp (action, "query_cookie")) {

        // Web request that delivers cookie value back here (to server); display it.
        get-cookie define name="customer_name"
        out-header default
        @Customer name is <<p-web name>>
        @<hr/>

    } else {
        out-header default
        @Unrecognized action<hr/>
    }

}


SEE ALSO:


Examples ( example_cookies   example_create_table   example_docker   example_form   example_hello_world   examples   example_sendmail   example_stock   example_upload_file   example_write_report  )  SEE ALL (documentation)



Copyright (c) 2022 DaSoftver LLC. Vely is a trademark of Dasoftver LLC. The software and information herein are provided "AS IS" and without any warranties or guarantees of any kind. Icons copyright PaweĊ‚ Kuna licensed under MIT. This web page is licensed under CC-BY-SA-4.0.