You are here

Drupal专业开发指南 第16章 常见任务

g089h515r806 的头像
Submitted by g089h515r806 on 星期日, 2009-08-23 16:12

 

下面是一些你使用会话或者修改会话设置的常见方式。
 
修改cookie的存活周期
    包含会话ID的cookie的存活周期,是由settings.php中的session.cookie_lifetime控制的,其默认值为2,000,000秒(大约23天)。如果将该值设为0,那么当用户关闭浏览器时,cookie将被立即销毁。
 
修改会话名字
    当将网站部署在多个子域名上面时,就会遇到一个关于会话的常见问题。由于每个站点为session.cookie_domain使用相同的默认值,默认情况下PHPSESSID的session.name也相同,用户发现他们在任何给定时间只能登录到一个站点上。通过为每个站点创建一个唯一的会话名字,Drupal就可以解决这个问题。这里作了一些修改,会话名字是基于网站基URL的MD5哈希。
 
    通过删除settings.php中的一行代码前面的注释符,并声明$cookie_domain变量的值,就可以绕过自动生成会话名字了。该变量的值只能包含字母数字字符。下面是settings.php中对应的部分:
 
/**
 * Drupal automatically generates a unique session cookie name for each site
 * based on on its full domain name. If you have multiple domains pointing at
 * the same Drupal site, you can either redirect them all to a single domain
 * (see comment in .htaccess), or uncomment the line below and specify their
 * shared base domain. Doing so assures that users remain logged in as they
 * cross between your various domains.
 */
# $cookie_domain = 'example.com';
 
注意Drupal中,Perl风格的注释符号(#)只用于settings.php,.htaccess, robots.txt文件中,而实际的Perl和shell脚本都放在scripts目录中。
 

老葛的Drupal培训班 Think in Drupal

Drupal版本: