Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

session destroy problem

Status
Not open for further replies.

gokeeffe

Programmer
Jan 11, 2005
170
IE
Is it possible to do the following I have a three step registration form and on the last page I have 2 buttons one will submit the details into a mysql database and destroy the session and log the user out while the other will submit the details and bring you back to step one to register more items. This is the step that concerns me I want to bring the user back to step one destroying 4 of the ten session variable, is this possible ie is it possible to destroy just some session variables while carry forward ones you want.

Here is the code I am using at present to destroy them all.

If possible could someone shoe me how.

Regards and Thanks


-------------------------------------------------------- Code --------------------------------------------

// If no first name variable exists, redirect the user.
if (!isset($_SESSION['username']))

{

header ("Location: . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/index.php");
ob_end_clean(); // Delete the buffer
exit(); // Quit the Script
}

else

{ // Log out the user

$_SESSION = array(); // Destroy the variables.
session_destroy(); // Destroy the session itself
setcookie (session_name(), '' , time()-300, '/' , '',0); // destroy the cookie
}


echo '<div id = "contentform">';

// Print a customized message
echo "<h1>You are now logged out.</h1>";

echo '</div>';
 
You don't need to destroy the whole session, you could simply unset the variables you want to clear, or even just set them to null/default values.

HTH,
Gavin
 
Excellent it worked easy when you know how !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top