Glad to hear that. You can place the code inside a special file, lets say authentication.php and then include this file into the header.php.
Basically, the page where the user will get redirectes back to. The uri you set in the link. That page will need to have the file included