Thanks for your reply.
I applied your advice and with a little bit of adjustment to what I had done before, it now works.
it has thrown up the problem that if user1 logs out and user2 logs in without closing the browser in between users, then user2's login attempt takes him straight to the logout page. There is no code on any html/php pages in the site that have a link to the logout page (it is done via js).
I assume that it is something to do the browser cache.
It shouldn't be a major problem but have you any advice?