BCAV_WEB Posted November 16, 2010 Share Posted November 16, 2010 Currently I have a Javascript button to close a tab window which is great, but annoying problem is when the user opens up the section again all the previous session errors are there. I have tried the following, which didnt work; [ function destroy() { window.open('destroyCode.php'); } <a href='javascript:window.close()' onclick="destroy()" ><img class='close' src='images/close.jpg' alt='Close Window' /></a> ] [ <?php session_unregister("add_customer_errors"); session_unregister("add_customer_form"); session_destroy(); ?> <html> <body onload="javascript:window.close()"> </body> </html> ] Any ideas of how to do it? I have got the session being unregistered if the data is correct and saved to the database. But what is the user wants to start and then changes there mind. Link to comment https://forums.phpfreaks.com/topic/218837-destroy-php-session-via-javascript/ Share on other sites More sharing options...
Rifts Posted November 16, 2010 Share Posted November 16, 2010 try making this your destroycode session_start(); session_unset(); session_destroy(); Link to comment https://forums.phpfreaks.com/topic/218837-destroy-php-session-via-javascript/#findComment-1135086 Share on other sites More sharing options...
BCAV_WEB Posted November 17, 2010 Author Share Posted November 17, 2010 But that destorys all my sessions, including the one that will keep the user logged in Link to comment https://forums.phpfreaks.com/topic/218837-destroy-php-session-via-javascript/#findComment-1135464 Share on other sites More sharing options...
BCAV_WEB Posted November 17, 2010 Author Share Posted November 17, 2010 Sorted it, turns out I had to start the session on that page to close the session's I wanted to close. Thanks for the help [ <?php session_start(); session_unregister("add_customer_errors"); session_unregister("add_customer_form"); ?> <html> <body onload="javascript:window.close()"> </body> </html> ] Link to comment https://forums.phpfreaks.com/topic/218837-destroy-php-session-via-javascript/#findComment-1135467 Share on other sites More sharing options...
kenrbnsn Posted November 17, 2010 Share Posted November 17, 2010 Do not use session_unregister, instead do <?php session_start(); unset($_SESSION['add_customer_errors']); unset($_SESSION['add_customer_form']); ?> Ken Link to comment https://forums.phpfreaks.com/topic/218837-destroy-php-session-via-javascript/#findComment-1135468 Share on other sites More sharing options...
Pikachu2000 Posted November 17, 2010 Share Posted November 17, 2010 The manual states that session_unregister() is deprecated. Link to comment https://forums.phpfreaks.com/topic/218837-destroy-php-session-via-javascript/#findComment-1135469 Share on other sites More sharing options...
BCAV_WEB Posted November 17, 2010 Author Share Posted November 17, 2010 ooppsss... my bad, howcome? Link to comment https://forums.phpfreaks.com/topic/218837-destroy-php-session-via-javascript/#findComment-1135498 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.