User name on each page

This problem is regarding User login and session. I want to display USERNAME and Logout on top of each page (like in forums) and whenver session expires user will be redirected to login page. i’m newbee and never worked on sessions. please provide the code snippest for this in php structual programing (not php oops).