SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 29 of 29
  1. #26
    SitePoint Member
    Join Date
    Jun 2004
    Location
    singapore
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, done that. But, the page will keep coming up even though i press the refresh button

    Quote Originally Posted by MarcusJT
    Ok, so firstly, ignore JSRS.

    Then add an onunload event to the framset page, which opens an external window, the URL of which is the logout page.

    That's it.


  2. #27
    SitePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nakatakyo,

    Have you considered setting an expires header on the document so that a reload would be a forced one (retrieves from server)? This would allow you to intercept the logout and note that the file request associated with it immediately follows, and take the appropriate action.

    Of possible interest: postings by a user at another forum suggest that WinXP SP2 is closing a page much faster, interfering with some scripts that rely on onunload.

  3. #28
    We like music. weirdbeardmt's Avatar
    Join Date
    May 2001
    Location
    Channel Islands Girth: Footlong
    Posts
    5,882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I found this script on the BBC website:

    Code:
    function bb(tsc){
    	var cookie = document.cookie;
    	var cookieArray = cookie.split('; ');
    	// Get timestamp stored in cookie
    	for (var loop=0; loop < cookieArray.length; loop++){
    		var nameValue = cookieArray[loop].split("=");
    		nameValue[0].toString();
    		if (nameValue[0].toString() == 'FP-TS'){
    			var cookieTime = nameValue[1];
    		}
    	}
    	//Get time stamp from js var formTime set in the tmpl
    	if (tsc){
    		var formTime = tsc
    	}
    	// Else check query string
    	else {
    		var url = document.location.toString();
    		var urlElements = url.split("?");
    		var queryStringElements = urlElements[1].split("&");
    		// Parse query string until we find tsc
    		for (var qsLoop=0; qsLoop < queryStringElements.length; qsLoop++){
    			var nameValuePair = queryStringElements[qsLoop].split("=");
    			if (nameValuePair[0] == "tsc"){
    				var formTime = nameValuePair[1];
    			}
    		}
    	}
    	formTime = parseInt(formTime);
    	cookieTime = parseInt(cookieTime);
    	//alert("formTime =" + formTime + " and cookieTime = " + cookieTime + "\nIf cookieTime is higher, alert shows");
    	if (formTime < cookieTime){
    		alert ("Sorry, you've clicked your 'back' or 'refresh' button of your web browser.\n\nPlease avoid these two buttons when filling in forms as they may wipe out information that you have already typed in.");
    		history.go(1);
    	}
    	return false;
    }
    http://www.bbc.co.uk/signon/sso_includes/bb.js
    I swear to drunk I'm not God.
    Matt's debating is not a crime
    Hint: Don't buy a stupid dwarf Clicky

  4. #29
    SitePoint Member
    Join Date
    Jun 2006
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Sitepoint Forum
    Warning! You are replying to a thread which is more than 57 months old. Please consider creating a new thread instead.
    LOL! yeah .. it is what happens when making deep search at SE and finding buried, forgotten, interesting posts so time to respawn this ...

    Quote Originally Posted by MarcusJT
    Here's the plan:

    - At the top of every script, set the session timeout to 30mins or whatever you want it to be normally.

    - Then, use the onunload or onbeforeunload events (in conjuction with the JSRS library that I gave the URL for earlier) to call a script which sets the session timeout to one minute or so.

    - You then need to catch the session expiry event (however you do it in PHP) and call your log out code when it occurs.


    Thus, if the user is leaving the site (by closing the window, or navigating to another site), then his session expires one minute later. If he is only refreshing the page, then as soon as the page is called, the session timeout is reset to its normal value, and he stays logged in!

    <SMUGMODE>Easy!</SMUGMODE>


    M@rco
    Yeah ! i like that; in a website already built (PHP) , i have to define session expiration, so when pages load or member triggered ajax action happens, then the session timestamp gets updated;

    A cronjob checks in shorter periods than the defined session expiration timeouts, the timestamps at sessions table, using a condition like :
    if current_time - timeout_threshold > last_access_timestamp then run a logout operation (at server)

    When member no longer will use site and logout, i want to know when a member uses the proper logout link, or simply uses close button, or maybe she cant use anything because browser, computer , whatever ... crashed ...

    onunload is quite the answer to the issue of closing browser window, allowing to launch a fire and forget ajax action to make logout at server side ..; but it is not the answer if wanting a member confirmation;

    onbeforeunload would allow a better control, the problem is that it is also fired when member will keep browsing within site .. it could be a refresh, or back button or a link ...,

    So as the quoted plan suggests , it is needed some server-side control; and i like the plan as it makes me thing considering timestamps in other sense, as i cant substract constant in the SQL query, so i store them as the future session expiration time, and then make scripts running checklogin to renew the expiration time (current_time + timeout_threshold), except the script ran by ajax action triggered at onbeforeunload, therefore i just need a variable to pass to checklogin function to know what kind of session extension is applied ...; and the answer to the matter of no autosession expiration at PHP : use a cronjob and run oftenly, checking if current_time > expiration_timestamp for each active session ( as much as not over loading server )


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
  •