本文整理汇总了Python中lib.drupy.DrupyPHP.session_name方法的典型用法代码示例。如果您正苦于以下问题:Python DrupyPHP.session_name方法的具体用法?Python DrupyPHP.session_name怎么用?Python DrupyPHP.session_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.drupy.DrupyPHP
的用法示例。
在下文中一共展示了DrupyPHP.session_name方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: write
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import session_name [as 别名]
def write(key, value):
# If saving of session data is disabled or if the client
# doesn't have a session,
# and one isn't being created ($value), do nothing.
# This keeps crawlers out of
# the session table. This reduces memory and server load,
# and gives more useful
# statistics. We can't eliminate anonymous session table rows
# without breaking
# the "Who's Online" block.
if (not session_save_session() or \
(php.empty(php.COOKIE[php.session_name()]) and php.empty(value))):
return True
result = db_result(db_query("SELECT COUNT(*) FROM {sessions} " + \
"WHERE sid = '%s'", key))
lib_database.query(\
"UPDATE {sessions} SET " + \
"uid = %d, cache = %d, hostname = '%s', " + \
"session = '%s', timestamp = %d WHERE sid = '%s'", \
lib_appglobals.user.uid, (lib_appglobals.user.cache if \
php.isset(lib_appglobals.user.cache) else ''), \
ip_address(), value, php.time_(), key)
if (lib_database.affected_rows()):
# Last access time is updated no more frequently than once
# every 180 seconds.
# This reduces contention in the users table.
if (lib_appglobals.user.uid and \
drupy_time() - lib_appglobals.user.access > \
variable_get('session_write_interval', 180)):
db_query("UPDATE {users} SET access = %d WHERE uid = %d", \
php.time_(), lib_appglobals.user.uid)
else:
# If this query fails, another parallel request probably got here first.
# In that case, any session data generated in this request is discarded.
lib_databae.query(\
"INSERT INTO {sessions} " + \
"(sid, uid, cache, hostname, session, timestamp) " + \
"VALUES ('%s', %d, %d, '%s', '%s', %d)", \
key, lib_appglobals.user.uid, (lib_appglobals.user.cache if \
php.isset(lib_appglobals.user.cache) else ''), \
ip_address(), value, php.time_())
return True
示例2: read
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import session_name [as 别名]
def read(key):
# Write and Close handlers are called after destructing objects
# since PHP 5.0.5
# Thus destructors can use sessions but session handler can't use objects.
# So we are moving session closure before destructing objects.
register_shutdown_function('session_write_close')
# Handle the case of first time visitors and clients that don't
# store cookies (eg. web crawlers).
if (not php.isset(_COOKIE, php.session_name())):
lib_appglobals.user = drupal_anonymous_user()
return ''
# Otherwise, if the session is still active, we have a record of
# the client's session in the database.
lib_appglobals.user = \
db_fetch_object(db_query("SELECT u.*, s.* FROM {users} u " + \
"INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.sid = '%s'", key))
# We found the client's session record and they are an authenticated user
if (lib_appglobals.user and lib_appglobals.user.uid > 0):
# This is done to unserialize the data member of user
lib_appglobals.user = drupal_unpack(lib_appglobals.user)
# Add roles element to user
lib_appglobals.user.roles = array()
lib_appglobals.user.roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user'
result = db_query("SELECT r.rid, r.name FROM {role} r " +
"INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid = %d", \
lib_appglobals.user.uid)
while True:
role = db_fetch_object(result)
if role == None:
break
lib_appglobals.user.roles[role.rid] = role.name
# We didn't find the client's record (session has expired),
# or they are an anonymous user.
else:
session = (lib_appglobals.user.session if \
php.isset(lib_appglobals.user.session) else '')
lib_appglobals.user = drupal_anonymous_user(session)
return lib_appglobals.user.session