Custom variables - sample code, please?

I found some examples of using custom variables to record the user’s loginID, but I could not make it work with my .jsp pages. If anyone has an example of pulling the LoginID, I would very much like to review the code. I tried using the example code with php, but it did not work correctly. Many thanks for any suggestions.