In addition to what Piranha said above, there is another reason we can't explain the code for you: we aren't psychic. Who knows what the method loadFromSession() does, or which class $thisUser is an instance of, or how that class even looks. Nor do we know where $ok came from at the very start of the script, so we don't know how the logic flow works, or... etc.
Ultimately, it would probably take a long time for you to go through all of this foreign code, try to learn what every little piece does, and then customize/tweak it in order to do what you want it to do. In fact, it would probably take less time if you instead started with what you do know and wrote a script from scratch (possibly using another pre-written script, like the one you have above, as a guide).
Minus frameworks, this is often true; it's hard to find a "one-size-fits-all" type of script that's easy to understand/use for your exact purposes.