Session question
| From: | Paul Halliday | Date: | Tue, 17 May 2011 10:52:06 +0000 |
| Subject: | Session question | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-312820@lists.php.net to get a copy of this message | ||
Is it OK to have session_start as an include?
I have something like this:
// Session init
session_start();
function sKill() {
session_destroy();
session_unset();
header ("Location: login.php");
exit();
}
function sInt() {
header ("Location: login.php");
exit();
}
if (!(isset($_SESSION['sLogin']) && $_SESSION['sLogin'] !=
'')) {
sKill();
}
// Session variables
if (!isset($_SESSION['sUser'])) { sInt(); } else { $sUser =
$_SESSION['sUser'];}
if (!isset($_SESSION['sEmail'])) { sInt(); } else { $sEmail =
$_SESSION['sEmail'];}
if (!isset($_SESSION['sType'])) { sInt(); } else { $sType =
$_SESSION['sType'];}
if (!isset($_SESSION['sTime'])) { sInt(); } else { $sTime =
$_SESSION['sTime'];}
if (!isset($_REQUEST['id'])) { $id = 0; } else { $id = $_REQUEST['id'];}
// Kill the session if the ids dont match.
if ($id != $_SESSION['id']) {
sKill();
}
// Kill the session if timeout is exceeded.
if (isset($_SESSION['LAST_ACTIVITY']) && (time() -
$_SESSION['LAST_ACTIVITY'] > $sTime)) {
sKill();
}
Can I just call this session.php and include it at the beginning of each file?
--
Paul Halliday
http://www.squertproject.org/