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.
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" } }, }
Anonymous
You seem to have CSS turned off. Please don't fill out this field.
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.
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;
};
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"
}
},
}
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.