PHP Code:
session_start();
// do whatever with the session variables, e.g.:
$_SESSION['foo'] = 'bar';
session_end();
session_start() will generate a new session ID if the user doesn't currently have a session. The way I do sessions for logging in is :-
PHP Code:
// dologin.php :
session_destroy(); // make sure we start a new session
session_start();
// check $_POST['password'] is ok
$_SESSION['username'] = $_POST['username'];
header('Location: main.php');
session_end();
PHP Code:
// main.php :
session_start();
if (!$_SESSION['username'] || $_SESSION['username'] == '') {
// No session or session is invalid - throw back to the login form
header('Location: index.php');
}
// Rest of page goes here
session_end();
That's a very simplistic set of scripts but it shows you the basics.
Hope this helps you.
Bookmarks