简体   繁体   English

如果禁用cookie,如何进行工作zend框架会话?

[英]how to make work zend framework session if cookies are disabled?

I am starting session with 我正在开始会议

$sess = new Zend_Session_Namespace('MySession');

and session works fine but problem comes when cookies are disabled in browser. 和会话工作正常,但在浏览器中禁用cookies时出现问题。 i have a big application , so what will be the best solution to make it work on cookie-less environment. 我有一个很大的应用程序,所以最好的解决方案是让它在无cookie环境中运行。

You could set the session.use_only_cookies to "0" and append the session ID to the URL in your code, so every link or redirect would have something like "session_id=4b5fe6a4019a8cd7fc4326664e9e03ae" appended to the URL. 您可以将session.use_only_cookies设置为“0”并将会话ID附加到代码中的URL,这样每个链接或重定向都会在URL中附加类似“session_id = 4b5fe6a4019a8cd7fc4326664e9e03ae”的内容。

This approach have many issues, the biggest one is that if a user decides to share an URL, lets say in Facebook, he/she would copy the whole url from the browser (including the session ID) and everyone who clicks that link will capture the user's session. 这种方法存在很多问题,最大的问题是,如果用户决定共享URL,让我们说在Facebook中,他/她会从浏览器中复制整个URL(包括会话ID),点击该链接的每个人都将捕获用户的会话。

Have a look at this . 看看这个

Instead of supporting cookie less browsers, you can display a warning on your login page that cookies are required. 您可以在登录页面上显示需要cookie的警告,而不是支持cookie少的浏览器。 many web application force you to have cookies enabled these days. 许多Web应用程序强迫您最近启用cookie。

// make sure cookies are enabled
$.cookie('test_cookie', 'cookie_value', { path: '/' });
if ($.cookie('test_cookie') != 'cookie_value') {
    noty({"text":"Cookies must be enabled to log in. <a href='http://support.google.com/accounts/bin/answer.py?hl=en&answer=61416' class='noty_link'>Click here to learn how to enable cookies.</a>","layout":"top","type":"error","textAlign":"center","easing":"swing","animateOpen":{"height":"toggle"},"speed":500,"closable":false, "closeOnSelfOver":false, "timeout":"", "closeOnSelfClick":false});
}

this code snippet uses jquery.cookie.js (https://github.com/carhartl/jquery-cookie) & noty (http://needim.github.com/noty/) plugin plugins 此代码段使用jquery.cookie.js(https://github.com/carhartl/jquery-cookie)和noty(http://needim.github.com/noty/)插件插件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM