Professional Web Applications Themes

unregister session onunload - PHP Development

I've got a dilemna that I'm hoping someone can help with. I've got a php page that allows users to select and deselect certain objects from an list that is in an array. The array is held in a php session because after each select/deselect a postback is made on the page, and by keeping the array in the session, I don't loose the data. Anyway, I'm also using javascript onunload to detect if the user attempts to leave the page before saving the settings (the select/deselects made). If the user attempts to leave the page they are presented with ...

  1. #1

    Default unregister session onunload

    I've got a dilemna that I'm hoping someone can help with.

    I've got a php page that allows users to select and deselect certain objects
    from an list that is in an array. The array is held in a php session because
    after each select/deselect a postback is made on the page, and by keeping
    the array in the session, I don't loose the data.

    Anyway, I'm also using javascript onunload to detect if the user attempts to
    leave the page before saving the settings (the select/deselects made). If
    the user attempts to leave the page they are presented with a javascript
    confirm popup box. They receive the message, "If you continue you will lose
    changes, blah, blah, or you can hit cancel....". If the user clicks on
    Cancel, they stay on the page, if the user clicks OK, they navigate away.
    All of this works fine...for the most part.

    Now the problem. If the user decided to navigate away from the page, I need
    to somehow unregister the PHP session. Because I'm using client-side
    javascript with confirm, I can't figure out how to do it. So all the options
    that were selected on the original page, are still present in the array in
    the php session.

    Anybody have an idea on this?

    Thanks for any help you can give.

    Max



    Max Guest

  2. #2

    Default Re: unregister session onunload

    Max wrote:

    <snip> 

    OK, as you've realised, you need to do something serverside. One solution
    would be to handle the 'unload' event on any page the user might navigate
    *to* when exiting the page associated with the stored data. This would be
    tricky to implement. One solution is to have a common include file on all
    scripts which processes actions from a hidden variable...e.g.

    <?php

    if ($_REQUEST['exit_action']) {
    include $_REQUEST['exist_action'];
    }

    ?>

    But this poses 2 problems:
    1) you need to ensure that this gets included in every script (PHP has an
    auto-prepend directive).

    2) you're skating on thin ice by allowing the browser to specify what code
    to run (consider encrypting the parameter)

    An alternative, and more self-contained approach would be to have the 'exit'
    javascript just set the URL of a hidden iframe. When the user wants to
    exit, this should fetch a URL which does the serverside stuff, then
    presents javascript to the browser to change the location.

    HTH

    C.
    Colin Guest

  3. #3

    Default Re: unregister session onunload

    > An alternative, and more self-contained approach would be to have the 

    With the hidden iframe, if the user selects a link to another page, the
    javascript confirm pops up, the user choses no for save changes, then the
    hidden iframe runs a php page that uregisters the session variable, correct?
    But does the user still navigate away to the page they were originally
    destined for?

    What I've got now is:

    if (!confirm(message)) {

    window.location=\"$self\"
    }

    Are you saying I need to add 'else' to the code above and direct to a hidden
    iframe? How is this done?

    Thanks,
    Max


    Max Guest

Similar Threads

  1. 'Unregister' AVAppRegisterAnnotHandler
    By Wolf_Horn@adobeforums.com in forum Adobe Acrobat SDK
    Replies: 1
    Last Post: July 13th, 06:42 PM
  2. There are ONUNLOAD limits?
    By Rafael in forum Informix
    Replies: 2
    Last Post: January 10th, 09:18 PM
  3. Onunload & onload question
    By Matthew Tan in forum Informix
    Replies: 3
    Last Post: October 22nd, 07:33 AM
  4. onunload event
    By RobGT in forum Macromedia Dreamweaver
    Replies: 1
    Last Post: July 10th, 01:17 PM
  5. GUI (windows) tool to register and Unregister databldes
    By Murali Nanduri in forum Informix
    Replies: 0
    Last Post: July 9th, 11:17 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139