Retired Documentation: You are using the documentation for version 1.7.3 which was retired in 2013. Go here for the latest version documentation or check here for your available upgrades to the latest version.
Session Class
Calling the Session Class
ExpressionEngine uses the Session class for storing information about the user currently visiting the ExpressionEngine site. If the user is a member and is logged in, then their various preferences and privileges are loading into variables, which are then immediately available throughout the entire program without the use of a query. To use the Session class in your modules, simply call the $SESS global in every function that will require the use of any text.
function session_example() { global $SESS; if ($SESS->userdata['group_id'] != 1) { exit('Not a Superadmin'); } else { $admin_email = $SESS->userdata['email'] } }
The Functions class has numerous functions that use the information in the Session class variables to provide useful information for modules and plugins, such as allowed weblogs and access to areas. Make sure to check out the Functions class reference file for more information on these functions
User Data Information
The $SESS->userdata variable is an array that contains information about that specific user, and it will likely be the most used part of this class for any module. Below is a list of the variables that it contains. NOTE: If a user has a group_id of 1, then they can access anything, no matter the other settings.
- username - Username of user
- screen_name - Screename of user, if any
- email - Email Address
- url - Homepage, if any
- location - Location, if any
- language - Chosen Language
- timezone - Chosen Timezone (UM12 - UTC - UP12)
- daylight_savings - y/n
- time_format - eu/us
- group_id - Group ID number (1-Superadmin, 2-Banned, 3-Guests, 4-Pending, 5-Members, 6+ Other Member Groups
- access_cp - y/n
- is_banned - 0/1
- weblog_id - Default weblog's weblog_id number
- tmpl_group_id - Default template's group_id number
- member_id - User's unique member_id
- last_visit - Last visit of user in Unixtime
- total_entries - Total entries
- total_comments - Total comments
- total_forum_posts - Total Forum Posts for User (sum of topics and replies)
- total_forum_topics - Total topics posted by user
- total_forum_replies - Total replies posted by user
- last_forum_post_date - Last time user posted in forum in GTM Unix timestamp
- profile_theme - Selected member profile theme, if blank then default
- forum_theme - Select forum theme, if blank then default
- private_messages - Number of unread private messages
- accept_messages - (y/n) Accept Private Messages
- display_signatures - (y/n)
- display_avatars - (y/n)
- last_email_date - Last time an email was sent
- notify_by_default - Notify of comments by default
- ignore_list - Array containing member_id's that the logged in user wishes to ignore
- group_title - Name of Group
- is_locked - (y/n) Is member group access locked and only available to Superadmins?
- can_view_offline_system - (y/n)
- can_view_online_system - (y/n)
- can_access_cp - (y/n)
- can_access_publish - (y/n)
- can_access_edit - (y/n)
- can_access_design - (y/n)
- can_access_comm - (y/n)
- can_access_modules - (y/n)
- can_access_admin - (y/n)
- can_admin_weblogs - (y/n)
- can_admin_members - (y/n)
- can_delete_members - (y/n)
- can_admin_mbr_groups - (y/n)
- can_admin_mbr_templates - (y/n)
- can_ban_users - (y/n)
- can_admin_utilities - (y/n)
- can_admin_preferences - (y/n)
- can_admin_modules - (y/n)
- can_admin_templates - (y/n)
- can_view_other_entries - (y/n)
- can_edit_other_entries - (y/n)
- can_assign_post_authors - (y/n)
- can_delete_self_entries - (y/n)
- can_delete_all_entries - (y/n)
- can_view_other_comments - (y/n)
- can_edit_own_comments - (y/n)
- can_delete_own_comments - (y/n)
- can_edit_all_comments - (y/n)
- can_delete_all_comments - (y/n)
- can_moderate_comments - (y/n)
- can_send_email - (y/n)
- can_send_cached_email - (y/n)
- can_email_members - (y/n)
- can_email_member_groups - (y/n)
- can_email_mailinglist - (y/n)
- can_email_from_profile - (y/n)
- can_view_profiles - (y/n)
- can_post_comments - (y/n)
- exclude_from_moderation - (y/n)
- can_search - (y/n)
- search_flood_control - Number of seconds between searches
- can_send_private_messages - (y/n)
- can_attach_in_private_messages - (y/n)
- include_in_memberlist - (y/n)
- display_photos - (y/n)
- session_id - Session ID number
- admin_sess - (0/1) Admin Session (0 => no, 1 => yes)
- ip_address - IP Address of user
- user_agent - HTTP User Agent of user
On the Control Panel side of ExpressionEngine a few more variables are included:
- theme - Chosen Control Panel theme
- quick_links - Quick Links for member
- template_size - Size of Template textarea
- assigned_weblogs - Array containing weblog_id's of assigned weblogs for member.
- assigned_modules - Array where the keys are the module_id's and the values determine if access is allowed (0 => no, 1=> yes). For Superadmins it will be empty, since they have unlimited access.
- assigned_template_groups - Assigned Template groups for member. Will be used for Community Blogs Module.
Tracker Array
The Session class has one more useful variable that is only available on the user side of the site. $SESS->tracker is an array that contains the last five ExpressionEngine pages viewed by this user in the form of a ExpresionEngine query string (i.e. '/weblog/comments/' or 'index' for main site page). The array's keys ranges from 0-5.
$current_page = $SESS->tracker['0']; $last_page = $SESS->tracker['1']; $two_pages_ago = $SESS->tracker['2'];
If a page is constantly reloaded, ExpressionEngine will not allow the array to fill up with just the page's query string but waits until the user visits another page before updating the tracker array.