Forum Discussion
Joern_Oltmann
Jan 30, 2013Nimbostratus
Thanks all for help,
Someone suggestions for improvement, now I will use this iRule.
when RULE_INIT {
log local0. "Running RULE_INIT of iRule 'global_tracking_cookie'"
Global Session Name
set static::globalSessionName "_global"
Session (Idle) timeout in seconds (10 year = 31536000 seconds)
set static::globalSessionTimeout 31536000
Header for New Global Session
set static::globalSessionHeader "X-Global-Session"
set static::globalSessionHeaderValueNew "new"
log local0. "iRule 'global_tracking_cookie' initialized: sessionName($static::globalSessionName), sessionTimeout($static::sessionTimeout)"
}
when HTTP_REQUEST {
if { not [HTTP::cookie exists $static::globalSessionName] } {
INFO: generate global tracking session
main_domain like "wlw.de"
set main_domain_pos 2
if { [string tolower [HTTP::host]] ends_with ".co.uk" } {
main_domain is "wlw.co.uk"
incr main_domain_pos 1
}
if { [string tolower [HTTP::host]] contains "onlinetest" } {
main_domain is "onlinetest.wlw.(de|co.uk)"
incr main_domain_pos 1
} elseif { [string tolower [HTTP::host]] contains ".webdev." } {
main_domain is "preview.webdev.wlw.(de|co.uk)"
incr main_domain_pos 2
}
set main_domain [domain [HTTP::host] $main_domain_pos]
set new_session_value "[string range [AES::key 128] 15 end][string range [AES::key 128] 15 end]"
set http header and cookie
HTTP::header insert $static::globalSessionHeader $static::globalSessionHeaderValueNew
HTTP::cookie insert name $static::globalSessionName value $new_session_value
cleanup
unset main_domain_pos
}
}
when HTTP_RESPONSE {
if { [info exists new_session_value] } {
INFO: transport the new global tracking cookie to the client
HTTP::cookie insert name $static::globalSessionName value $new_session_value domain $main_domain
HTTP::cookie expires $static::globalSessionName $static::globalSessionTimeout
cleanup
unset main_domain new_session_value
}
}