Zend Authentication Problem with subdomain

删除回忆录丶 提交于 2019-12-09 23:20:17

问题


I am working on a project using zend framework, php, mysql on ubuntu.

I have created hostname test.dev on my local machine and using zend authentication. When an user is authenticated using zend authentication, I set session variable for logged in user id. I use this session variable(userid) on different pages to sure authentication.

Question: Now I have to create a subdomain. I have created a new hostname mypage.test.dev on my local machine. Both hostnames are pointing to same directory, for example /var/www/test/public. But when I login on test.dev, I have to login again on subdomain mypage.test.dev. Even session variables of test.dev are not accessable on mypage.test.dev.

How can I login on all subdomains using one login?

Thanks.


回答1:


Session variables are stored specific to each specific domain address. And so if a website is coded poorly and you login to http://mydomain.com and then later access the site as http://www.mydomain.com, you will encounter the same error.

One possible solution to this is to setup a webservice that allows you to access the other domain and retrieve any stored session variables as well as authenticate the user. So for example, if I login to test.dev and then later go to mypage.test.dev, a call will be issued to test.dev/auth-service/ by mypage.test.dev to authenticate the user and if it is successful, then return all stored session variables so that they can be stored by mypage.test.dev.

Perhaps a cleaner approach would be to always access session data only from one domain or the other and to always access it strictly through the web service so that the interface to session data remains consistent across both sites. This does present a possible performance though since it is obviously faster to simply access session directly rather than through a web service.




回答2:


You are looking for this: http://blog.pracucci.com/2008/09/24/zend-framework-and-session-cookies-across-subdomains/




回答3:


After some time I have got my solution.

I added following line into config.ini

session.cookie_domain = .test.dev

then added the following line into Bootstrap.php

Zend_Session::setOptions( $this->getOption('session') );

and session variables are working for all subdomains of test.dev



来源:https://stackoverflow.com/questions/1781453/zend-authentication-problem-with-subdomain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!