thanks for your help everyone. I managed to come up with a solution using javascript and cookies:

when the user logs in a cookie is created. when the user logs out the cookie is deleted. in the onload of every page a javascript function is run which looks to see if the cookie exists. if it doesn't then the user is redirected to the log in page. quite simple really. not sure why it was giving me such a headache