did you add that same code to the admin/index.php page? The access restriction code should not be on the admin/index.php page.
are the secured pages in the admin folder? or a subfolder of the admin folder? if they are in a subfolder of the admin folder, the redirect to the index page would need to be modified to account for that: