You can log a user out after x number of minutes of inactivity, ie no new page loads, using php alone but its also a good idea to let the user see they have been logged out when it happens which requires just a bit of Javascript.
First the Javascript code. This gets placed in the head section of the html code and it will be responsible for causing a page refreshed when the inactivity logout occurs. Although this is not absolutely required.
This code gets placed between the <head>
and </head>
tags at the top of your web page.
This php code gets placed at the very top of the page. Might be a good idea to put this code in a separate file ie sessionstart.php and call it into the beginning of the web page via include "path-to-sessionstart-file/session-start.php";
.