Hi,
I used an older tutorial on how to create a user login and secure area with sessions. I just realised that 'session_register' is not advised now. I am trying to update this code now but don't know how to handle 'SESSION' . I guess i could just set a $_SESSION variable in login.php and then check if that variable exsits in the other secure pages like inside.php but i feel that there is a better way. Any help is appreciated.

Chuck

<?PHP
// login.php - performs validation
$username       = $_POST[user];
$password        = $_POST[pass];
$status = authenticate($username, $password);

// if user/pass combination is correct
if ($status)
{	// set path to save sessions
	//session_save_path("$path/sessions");	

// initiate a session
session_start();
header("Cache-control: private");

// register some session variables
session_register("SESSION");

// including the username
$_SESSION['username'] = $username; 

// redirect to protected page
header("Location: ../login/inside.php");
exit();
}
?>

<?PHP
// inside.php - secure page

// set path to save sessions
//session_save_path("$path/sessions");	

// session check
session_start();
if (!session_is_registered("SESSION"))
{	// if session check fails, invoke error handler
	header("Location: ../login/error.php?e=2");
	exit();
}
$username  = $_SESSION['username']; 
?>


<?PHP
// logout.php - destroys session and returns to login form
// destroy all session variables

// set path to save sessions
//session_save_path("$path/sessions");	

session_start();
session_unset();
session_destroy();
// redirect browser back to login page
header("Location: ../login/");
?>

    login.php

    <?
    $username = $_POST['user'];
    $password = $_POST['pass'];
    $status = authenticate($username, $password);
    
    if ($status) 
    {
    	session_start();
    	header('Cache-control: private');
    	$_SESSION['username'] = $username;
    	$_SESSION['password'] = $password;
    	$_SESSION['status'] = $status;
    	header('location: ../login/inside.php');
    	exit();
    } 
    ?>
    

    inside.php

    <?
    session_start(); 
    
    if (!isset($_SESSION['status']))
    {
    	header('location: ../login/error.php?e=2');
    	exit();
    } 
    
    // show private stuff here
    ?>
    

    logout.php

    <? 
    session_start();
    session_destroy();
    header('location: ../login/');
    exit(); 
    ?>
    
      Write a Reply...