php - clearing two dimensional session array using jsp

967

i have a two dimensional session array and i'm trying to clear it after the bill is printed. to do so i'm using this code

<script type="text/javascript">
    function textsizer(e) {
    var evtobj=window.event? event : e;
    var element = evtobj.target ? evtobj.target : evtobj.srcElement;
    if (element.tagName.toLowerCase() == "body") {
        var unicode=evtobj.charCode? evtobj.charCode : evtobj.keyCode;
        var actualkey=String.fromCharCode(unicode)
        if(actualkey=="x"){
            show_confirm()
            function show_confirm(){
            var con = confirm("Are You Sure you wan to cancel this bill?");
            if (con ==true){
                session.invalidate();
            }
            else{
            alert("You pressed Cancel!");
            }
            }
        }
    }
}
document.onkeypress=textsizer
</script>

but this code is not clearing the session. i tried it using google chrome and internet explorer but didn't work. can anyone help me on this thing? i also tried to do it with php but it also didn't work for me. my case i want to delete session by pressing x on key board there is no matter what is the language, i just want to clear the session pressing x key

193

Answer

Solution:

You could use JavaScript to capture when the 'x' key is pressed, and redirect to a PHP page to clear the session. So you want something along the lines of:

//Your main page
<script type='text/javascript'>
window.onkeypress = function() {
    if (event.keyCode == 88) {
        window.location = 'clear_session.php';
    }
}

//clear_session.php
session_start();
session_unset();
session_destroy();
header ("Location:main_page.php"); //redirect back to main page

People are also looking for solutions to the problem: wordpress - Combine these basic php functions

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.