Sorry for the delay in responding. Had a meeting. See below and files attached.
If I use the link 'Log in' to check access and pass the URL, then the got to previous URL doesn't work, but if I try to access a page that is protected, then I get redirected to login.php and then back to the initial URL as expected. I've obviously missed something minor in my login link I think, but don't know what.
PS... just a thought, in the detail page I've attached, do I need to reference the security assist helper?