Add new checklogin function and update index.php to make use of it