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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot destroy php session variable

Status
Not open for further replies.

sallieann

Programmer
Sep 2, 2003
28
GB
I am trying to destroy a session variable in php from logout.php using the following commands

session_unregister("valid_user");
session_unset();
session_destroy();

I have set the session on login.php with the following

session_start();
$valid_user = $email;
session_register("valid_user");
$temp_session = session_id();

When I logout and then login again, the same session id is applied. Could anyone give me a pointer as to why a new session id is not given.
 
I strongly recommend that you not use session_register() and session_unregister().

Rather, I recommend that you manipulate session variables by adding, changing or removing elements from the $_SESSION superglobal array directly. This is because session_register(), in order to work, requires that the PHP runtime configuration directive register_globals be set to "on", which is a security issue.

Try the following three scripts on for size:

test_session_delete1.php:
Code:
<?php
session_start();

$_SESSION['foo'] = 'bar';
$_SESSION['bar'] = 'baz';

print '<html><body><a href="test_session_delete2.php">next</a></body></html>';
?>

test_session_delete2.php:
Code:
<?php
session_start();

print '<html><body>Before deletion:<pre>';

print_r ($_SESSION);

print '</pre><a href="test_session_delete3.php">next</a></body></html>';

unset ($_SESSION['foo']);
?>

test_session_delete3.php:
Code:
<?php
session_start();

print '<html><body>After deletion:<pre>';

print_r ($_SESSION);

print '</pre></body></html>';
?>


Which sets and deletes the session variables nicely.




Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top