Forum Discussion

Erika_I_Garner's avatar
Erika_I_Garner
Icon for Altostratus rankAltostratus
Oct 13, 2017

parse username

I am trying to get only the UserID with the following iRule, but I end up getting it and also the password and I only want the UserID. Can someone help me, this is driving me crazy!

when HTTP_REQUEST_DATA { if {([HTTP::payload] contains "UserID")} { set UserID "unknown" foreach x [split [[HTTP::payload]] "&"] { if { $x starts_with "UserID=" } { set UserID [lindex [split $x "="] 1] } }

log local0. "User $UserID attempted login from [IP::client_addr]   and referer:  [HTTP::header "Referer"]"

} }

And I get the following result:

TCL error: /Common/LOG-User - invalid command name "UserID=abcdef&Password=password1234&destination=&saveDestination=false" while executing "[HTTP::payload]"

2 Replies

  • Updated iRule using findstr...

    when HTTP_REQUEST_DATA { 
      Set UserID [findstr [HTTP::payload] "UserID=" 7 "&"]  
      log local0. "User $UserID attempted login from [IP::client_addr]   and referer:  [HTTP::header "Referer"]"
    }    
    

    Does that work better for you?

  • Hi,

     

    you can use following code:

     

    when HTTP_REQUEST_DATA { 
      set UserID [URI::query "?[HTTP::payload]" "UserID"]  
      log local0. "User $UserID attempted login from [IP::client_addr]   and referer:  [HTTP::header "Referer"]"
    }