Menu

#152 Session don't work

cppcms-v1.0.x
pending
nobody
None
1
2018-05-30
2018-05-28
Renjith CJ
No

Please Help...
I'm new in software field. I am create an application in angular js, and cppcms used for the back end.
when tried to check session().is_set() after login page it shows 0. sample code is given below.

1 Attachments

Discussion

  • Renjith CJ

    Renjith CJ - 2018-05-28

    This is my sample code,

    class hello : public cppcms::application {
    public:
    hello(cppcms::service &srv) :
    cppcms::application(srv)
    {
    dispatcher().assign("/login.php", &hello::login, this);
    dispatcher().assign("/mango.php", &hello::mango, this);
    dispatcher().assign("/apple.php", &hello::apple, this);
    }
    void login()
    {
    if (request().request_method() == "POST")
    {
    ........
    .......
    ........
    session()["name"]=username;

            std::cout << session().is_set("name") << std::endl;  //it shows 1
        }
    }
    void mango()
    {
        std::cout << session().is_set("name") << std::endl;  //it shows 0
    }
    void apple()
    {
        std::cout << session().is_set("name") << std::endl;  //it shows 0
    }
    

    };

    int main(int argc, char ** argv)
    {
    try {
    cppcms::service srv(argc, argv);
    srv.applications_pool().mount(
    cppcms::applications_factory<hello>()
    );
    srv.run();
    }
    catch (std::exception const &e) {
    std::cerr << e.what() << std::endl;
    }
    }

    This is config.js file,

    {
    "service" : {
    "api" : "http",
    "port" : 8080
    },
    "http" : {
    "script" : "/hello"
    },
    "session" : {
    "expire" : "fixed",
    "timeout" : 604800,
    "location" : "client",
    "client" : {
    "hmac" : "sha1",
    "hmac_key" : "3891bbf7f845fd4277008a63d72640fc13bb9a31"
    }
    },
    }

     
  • Artyom Beilis

    Artyom Beilis - 2018-05-30

    From your partial "sample" it seems that modifing session is the last thing you do.

    You can't change session values once output was generated:

    once you call response().out() - all headers (including session data) are generated.

     
  • Artyom Beilis

    Artyom Beilis - 2018-05-30
    • status: open --> pending
     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.