Forum Discussion
Possible to put parameter from an URL into a cookie?
Hi, it is possible to search on an URL to one or more parameters, and when the parameters are found, set a cookie with the value of the parameter?
Thanks for answer.
Joern
12 Replies
- Brad_Parker
Cirrus
Absolutely possible. Are you wanting to send cookies back to the client in the response with the values they supplied in the request?
- Joern_Oltmann
Nimbostratus
Exactly :-) Do you have an example for me or an URL with the information how it is possible? Would be great !
- Brad_Parker_139
Nacreous
Absolutely possible. Are you wanting to send cookies back to the client in the response with the values they supplied in the request?
- Joern_Oltmann
Nimbostratus
Exactly :-) Do you have an example for me or an URL with the information how it is possible? Would be great !
- Brad_Parker_139
Nacreous
Could be as simple as this. The request is http://your.domain.name/your/path?param1=this¶m2=that. The user would get session cookies param1CookieName=this and param2CookieName=that
when HTTP_REQUEST { set param1Cookie [URI::query [string tolower [HTTP::uri]] param1] set param2Cookie [URI::query [string tolower [HTTP::uri]] param2] } when HTTP_RESPONSE { if {$param1Cookie ne ""}{ HTTP::cookie insert name param1CookieName value $param1Cookie } if {$param2Cookie ne ""}{ HTTP::cookie insert name param2CookieName value $param2Cookie } }- Joern_Oltmann
Nimbostratus
Looks cool, I will try it. Thx a lot.
- Brad_Parker
Cirrus
Could be as simple as this. The request is http://your.domain.name/your/path?param1=this¶m2=that. The user would get session cookies param1CookieName=this and param2CookieName=that
when HTTP_REQUEST { set param1Cookie [URI::query [string tolower [HTTP::uri]] param1] set param2Cookie [URI::query [string tolower [HTTP::uri]] param2] } when HTTP_RESPONSE { if {$param1Cookie ne ""}{ HTTP::cookie insert name param1CookieName value $param1Cookie } if {$param2Cookie ne ""}{ HTTP::cookie insert name param2CookieName value $param2Cookie } }- Joern_Oltmann
Nimbostratus
Looks cool, I will try it. Thx a lot.
- Joern_Oltmann
Nimbostratus
Hi Brad, the iRule works fine if you have no redirect. But we need also the cookies for a redirect. So the cookies must be insert in the location header
For example: is redirected to "Location " but we need the following Location "Location "
Also if the lacation url has no parameter it must look like these
"Location &cusid=123456&comid=654321"
Does anyone have a suggestion for me??
- Joern_Oltmann
Nimbostratus
If anyone interested, I found the solution:
when HTTP_REQUEST {
set param_domain [domain [HTTP::host] 2] set param_wlw_comid [URI::query [string tolower [HTTP::uri]] comid] set param_wlw_cusid [URI::query [string tolower [HTTP::uri]] cusid]}
when HTTP_RESPONSE {
if { ($param_wlw_comid ne "") and ($param_domain ne "") }{ HTTP::cookie insert name wlw_comid value $param_wlw_comid path "/" domain $param_domain HTTP::cookie expires wlw_comid 31557600 } if { $param_wlw_cusid ne "" and ($param_domain ne "") }{ HTTP::cookie insert name wlw_cusid value $param_wlw_cusid path "/" domain $param_domain HTTP::cookie expires wlw_cusid 31557600 }}
- Joern_Oltmann
Nimbostratus
If anyone interested, I found the solution:
when HTTP_REQUEST {
set param_domain [domain [HTTP::host] 2] set param_wlw_comid [URI::query [string tolower [HTTP::uri]] comid] set param_wlw_cusid [URI::query [string tolower [HTTP::uri]] cusid]}
when HTTP_RESPONSE {
if { ($param_wlw_comid ne "") and ($param_domain ne "") }{ HTTP::cookie insert name wlw_comid value $param_wlw_comid path "/" domain $param_domain HTTP::cookie expires wlw_comid 31557600 } if { $param_wlw_cusid ne "" and ($param_domain ne "") }{ HTTP::cookie insert name wlw_cusid value $param_wlw_cusid path "/" domain $param_domain HTTP::cookie expires wlw_cusid 31557600 }}
- Joern_Oltmann
Nimbostratus
If anyone interested, I found the solution:
when HTTP_REQUEST {
set param_domain [domain [HTTP::host] 2] set param_wlw_comid [URI::query [string tolower [HTTP::uri]] comid] set param_wlw_cusid [URI::query [string tolower [HTTP::uri]] cusid]}
when HTTP_RESPONSE {
if { ($param_wlw_comid ne "") and ($param_domain ne "") }{ HTTP::cookie insert name wlw_comid value $param_wlw_comid path "/" domain $param_domain HTTP::cookie expires wlw_comid 31557600 } if { $param_wlw_cusid ne "" and ($param_domain ne "") }{ HTTP::cookie insert name wlw_cusid value $param_wlw_cusid path "/" domain $param_domain HTTP::cookie expires wlw_cusid 31557600 }}
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com