Saturday, 14 September 2013

Is it acceptable to open and then close the session for an external module?

Is it acceptable to open and then close the session for an external module?

I'm writing a small reusable user manager for my projects that will use
services as facebook, persona.org for login. From the point of view of
each web, it's an include and a couple of echoes. However, it uses
$_SESSION, so I need it initialized. For that I use this code in
'include.php':
<?php
if(session_id() == '') {
if (headers_sent()) {
throw new Exception ("You must include this file before sending any
header.");
}
session_start();
$NoSession = 1; // Leave everything as it was before
}
// MAIN CODE HERE
if ($NoSession) {
session_destroy();
}
Is it a good idea to destroy the session with session_destroy() or is it
acceptable to leave the session opened?

No comments:

Post a Comment