How to Print/Echo the Moodle Sesskey (Session Key)

Whilst developing some custom pages I wanted to create a custom link to login as a particular user.  In order to login as a user you need a couple of variables, the users moodle id, and the your session key.

To print/echo the session key within Moodle you need the following line of code :-

echo $USER->sesskey;