Use this:
<?php
if(!session_id()){
header('Location: /index.php');
exit;
}
?>
Just place it at the top of your html file
Or to be on the safe side, check if an index in the session is set like:
if(!isset($_SESSION['user'])){
// redirect code
}
For this to work, on user login, you need to set
$_SESSION['user'] = 'something'; // a real value here!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…