Forum Discussion

Joern_Oltmann's avatar
Joern_Oltmann
Icon for Nimbostratus rankNimbostratus
Mar 08, 2016

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

  • 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's avatar
      Joern_Oltmann
      Icon for Nimbostratus rankNimbostratus
      Exactly :-) Do you have an example for me or an URL with the information how it is possible? Would be great !
  • 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's avatar
      Joern_Oltmann
      Icon for Nimbostratus rankNimbostratus
      Exactly :-) Do you have an example for me or an URL with the information how it is possible? Would be great !
  • 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
        }
    }
    
  • 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
        }
    }
    
  • 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??

     

  • 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
    }
    

    }

  • 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
    }
    

    }

  • 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
    }
    

    }