Results 1 to 10 of 10

Thread: [RESOLVED] Prevent Window from Closing

  1. #1

    Thread Starter
    Addicted Member _Yoyo's Avatar
    Join Date
    Apr 2001
    Location
    Dominican Republic
    Posts
    187

    Resolved [RESOLVED] Prevent Window from Closing

    Hi!

    How can I, from PHP, prevent a window to be closed? I mean, if certain condition is met (a cookie exists for instance) write some javascript or whatever to prevent the browser to be closed before some action is executed...

    Code:
    If(cookie)
       do not allow window to be closed because session details gotta be saved to a DB before that;
    else
      Go ahead, close it!;
    The biggest man you ever did see was once just a baby.

    Bob Marley

  2. #2
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Ubuntu Haters Club
    Posts
    405

    Re: Prevent Window from Closing

    As far as I can see, you answered your own question.. Or do you want an implementation example?
    » Twitter: @rudi_visser : Website: www.rudiv.se «

    If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.

  3. #3
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Prevent Window from Closing

    IMO it's a waste of time. Trying to prevent the window closing is just going to annoy users.

    Aside from that, even if you are successful using Javascript, some users may be using a browser that does not support Javascript, or they may simply have it disabled. They may even have cookies disabled or blocked for untrusted websites.

    I suggest you just use some sort og Logout button, which can direct to a page that executes your set cookie code.
    Chris

  4. #4

    Thread Starter
    Addicted Member _Yoyo's Avatar
    Join Date
    Apr 2001
    Location
    Dominican Republic
    Posts
    187

    Re: Prevent Window from Closing

    Quote Originally Posted by the182guy
    IMO it's a waste of time. Trying to prevent the window closing is just going to annoy users.

    Aside from that, even if you are successful using Javascript, some users may be using a browser that does not support Javascript, or they may simply have it disabled. They may even have cookies disabled or blocked for untrusted websites.

    I suggest you just use some sort og Logout button, which can direct to a page that executes your set cookie code.
    The disabling of javascript or cookies is not an issue. I got that covered. My users often careless about buttons, so i'm losing log data everytime they don't use the 'logout' button.

    Some working code would be of great help
    The biggest man you ever did see was once just a baby.

    Bob Marley

  5. #5
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Ubuntu Haters Club
    Posts
    405

    Re: Prevent Window from Closing

    Should you care to explain your *actual* issue further, we may be able to assist you in finding a more suited solution.
    » Twitter: @rudi_visser : Website: www.rudiv.se «

    If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.

  6. #6

    Thread Starter
    Addicted Member _Yoyo's Avatar
    Join Date
    Apr 2001
    Location
    Dominican Republic
    Posts
    187

    Re: Prevent Window from Closing

    Thanks for answering. Everytime a user log into the system, I record to a DB user, date log in, time log in, date log out and time logout. As you may know by now, when they log in I can record the data, but if they just decide to close the browser ignoring the "log Out" button, date logout and time logout won't be recorded.
    The biggest man you ever did see was once just a baby.

    Bob Marley

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Prevent Window from Closing

    You can derive the logout time as (last action time + session time-to-live). TTL is arbitrary; usually defined as 15 minutes or thereabouts.

  8. #8

    Thread Starter
    Addicted Member _Yoyo's Avatar
    Join Date
    Apr 2001
    Location
    Dominican Republic
    Posts
    187

    Re: Prevent Window from Closing

    Thaks for the response penagate. Would you please give me an example of what you're talking about
    The biggest man you ever did see was once just a baby.

    Bob Marley

  9. #9
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Prevent Window from Closing

    Well, if you record every authenticated page request in a database along with a timestamp, then you shouldn't need an automatic log out facility.

    Add this to every public page:
    PHP Code:
    require 'includes/log.php'
    log.php:
    PHP Code:
    <?php
      
    # some code to prevent this file from being requested directly
      # ...

      
    sql(
        
    'INSERT INTO accesslog (userid, pageuri) VALUES (?,?)',
        
    $userid,
        
    $_SERVER['REQUEST_URI']
      );
    ?>
    Something like that. Vary according to taste.

  10. #10

    Thread Starter
    Addicted Member _Yoyo's Avatar
    Join Date
    Apr 2001
    Location
    Dominican Republic
    Posts
    187

    Thumbs up Re: Prevent Window from Closing

    Awesome idea! Thanx!!!!
    The biggest man you ever did see was once just a baby.

    Bob Marley

Posting Permissions

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



Click Here to Expand Forum to Full Width