Collections functions
Encryption functions
General functions
Theme permission functions
Resource functions

set_login_cookies()

Description

Set login cookies

Parameters

ColumnTypeDefaultDescription
$user integer User ref
$session_hash string User session hash
$language string "" Language code (e.g en)
$user_preferences boolean Set colour theme from user preferences

Return

void

Location

include/login_functions.php lines 198 to 230

Definition

 
function set_login_cookies($user$session_hash$language ""$user_preferences)
    {
    global 
$baseurl$baseurl_short$allow_keep_logged_in$default_res_types$language;
    
$expires=0;
    if (
$allow_keep_logged_in && getval("remember","")!="") {$expires 100;} # remember login for 100 days
            
    
if($language != "")
        {
        
# Store language cookie
        
rs_setcookie("language"$language1000); # Only used if not global cookies
        
rs_setcookie("language"$language1000$baseurl_short "pages/");
        }
        
    
# Set the session cookie. Do this for all paths that nay set the cookie as otherwise we can end up with a valid cookie at e.g. pages/team or pages/ajax
    
rs_setcookie("user"""0$baseurl_short);
    
rs_setcookie("user"""0$baseurl_short "pages");
    
rs_setcookie("user"""0$baseurl_short "pages/team");
    
rs_setcookie("user"""0$baseurl_short "pages/admin");
    
rs_setcookie("user"""0$baseurl_short "pages/ajax");

    
# Set user cookie, setting secure only flag if a HTTPS site, and also setting the HTTPOnly flag so this cookie cannot be probed by scripts (mitigating potential XSS vuln.)    
    
rs_setcookie("user"$session_hash$expires$baseurl_short""substr($baseurl,0,5)=="https"true);

    
# Set default resource types
    
rs_setcookie('restypes'$default_res_types);

    
$userpreferences = ($user_preferences) ? sql_query("SELECT user, `value` AS colour_theme FROM user_preferences WHERE user = '" escape_check($user) . "' AND parameter = 'colour_theme';") : FALSE;
    
$userpreferences = ($userpreferences && isset($userpreferences[0])) ? $userpreferences[0]: FALSE;
    if(
$userpreferences && isset($userpreferences["colour_theme"]) && $userpreferences["colour_theme"]!="" && (!isset($_COOKIE["colour_theme"]) || $userpreferences["colour_theme"]!=$_COOKIE["colour_theme"]))
        {
        
rs_setcookie("colour_theme"$userpreferences["colour_theme"],100"/"""substr($baseurl,0,5)=="https"true);
        }
    }

This article was last updated 11th July 2020 02:35 Europe/London time based on the source file dated 30th June 2020 17:06 Europe/London time.