CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 [RESOLVED] Prompt with option to renew session about to expire

Print topic Send  topic

Author Message
karen

Posts: 99
Posted: 05/04/2011, 12:19 AM

Hi all,

Does anyone know how to incorporate into a form, a prompt that will detect when the session is about to expire and provide an option to renew the session? This is for users who take a long time to fill up the form with the result of losing all their entries when the session expires and they are asked to login again.

I would love to hear the different ideas how people handle this. Thanks in advance for any suggestions or advice.

Cheers,
Karen
CCS3, PHP5, MySQL5
View profile  Send private message
damian

Posts: 838
Posted: 05/04/2011, 4:49 PM

i dont know how to extend a session without submitting/refreshing a page... there are a numer of posts here that discuss work arounds including increasing session limit (in php.ini or htaccess), iframes which auto refresh, js reminders that the session will expire.
_________________
if you found this post useful take the time to help someone else.... :)
View profile  Send private message
karen

Posts: 99
Posted: 05/04/2011, 6:42 PM

Thanks for your response, Damian. I've actually searched around this forum but haven't really found something I can put to use. I've also tried googling this but not quite sure how to apply those ideas in CCS.

Increasing the session limit is not an option as sessions should timeout for those that are idle. I'm not sure how the iframes idea work and I think using a js alert with timer will work for prompting but not extending the session. With only a prompt, the user will still lose the data that has been entered into the form if they still have a long way to go. Which was why I thought that having an option to extend the session is a good idea.

I like the idea of using JS with timer to alert the user with option to renew session and if required, to make an AJAX request to a PHP file which uses sessions. But the confirmation has to be closed automatically if the user does not respond when the session has timed out. The only problem is that I don't know how to do this in CCS. Do you think this is feasible?

The other thing I read is in the PHP manuals about using the function session_set_cookie_params. Again I'm not sure how to make use of that in CCS forms so as not to break something else.

My last resort would be to save all the form details temporarily while the user logs in again but that would be really tedious with so many fields and I'm not even sure where to temporarily save it once the session is expired.

Any more thoughts on this would be much appreciated. Thanks in advance.

Cheers,
Karen
View profile  Send private message
jjrjr2


Posts: 131
Posted: 05/04/2011, 9:38 PM

Hmmm..

This sounds interesting.

I wonder is an ajax call to a dummy page on the server would keep a session alive...

I think I am gonna experiment with that when I have a chance...

Gonna look for some Javascript that can detect an expiring session.

Might be fun.
:-D

_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
Real Web Development At: http://RealWebDevelopment.us
View profile  Send private message
karen

Posts: 99
Posted: 05/05/2011, 4:03 AM

Hi John,

I hope you've got some ideas where to start. I would experiment with this too except I don't know where to start. So I would love to hear your ideas.

I didn't expect to use Javascript to detect an expiring session. I thought of just using a set timer knowing the server session setting, e.g., 20mins given the session gc_maxlifetime is 24mins. So once the JS timer of 20mins is up, use a confirm to check if the user would like to extend the session. Something along those lines?

If you have a simpler idea, I would love to try it out. Thanks again for taking an interest in this.

Cheers,
Karen
View profile  Send private message
karen

Posts: 99
Posted: 05/05/2011, 5:01 AM

Hi all,

I just googled a bit more and found this. http://www.jensbits.com/2009/09/07/session-timeout-warn...-with-jqueryjs/

Pls can some CCS expert point me in the right direction if this can be feasibly applied to a CCS project. Pls help get me started to experiment. Thanks in advance.

Cheers,
Karen
View profile  Send private message
jjrjr2


Posts: 131
Posted: 05/05/2011, 5:35 AM

Hi karen

That URL is pretty complete.. I have not tried it yet..

Howerver is it the PHP piece ofr theJavascript Piece U R wondering about?


_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
Real Web Development At: http://RealWebDevelopment.us
View profile  Send private message
Waspman

Posts: 948
Posted: 05/05/2011, 7:35 AM

Hey Karen! love that...gona be using on my next project ;-)


Sorry just read your post properly.

All you have to do is in the demo page. Take a look at the source.


T
_________________
http://www.waspmedia.co.uk
View profile  Send private message
datadoit
Posted: 05/05/2011, 9:52 AM

Careful here. Looks like the script reloads the page. That won't work
for you since it'll wipe out any information they may have already
entered into the form.

I'm leaning more towards the temporary file idea and using AJAX to
periodically write to the file (instead of reloading as in the example,
do an AJAX call). You can use session_id() as the primary key. Create
a server script to clean up the file periodically of stale sessions.
Waspman

Posts: 948
Posted: 05/05/2011, 10:51 AM

You right DD (of course:)

I'd still use it and embed in the page with a simple jquery script. Like I do with the chat system. It'll only refresh itself then. You could stick in an included page and use across the site.
_________________
http://www.waspmedia.co.uk
View profile  Send private message
karen

Posts: 99
Posted: 05/05/2011, 4:24 PM

Thanks for all the responses. I'll have to take a closer look at the code to see if I know where to put everything in CCS. It would probably be more of the PHP code that I will need to integrate with CCS.

Thanks for pointing out that the script reloads the page, I was wondering about that although it wasn't obvious from the demo as there are no fields to enter. I have no idea where to start with the AJAX call to a temporary file. I just found the idea but not sure what to do.

How about saving the fields to sessions and reload the page? Would that work? It would be tedious but more straightforward within CCS?

I also like the sound of using the script in an include page. But I'll have to work it out generally first.

I'll study the script and hope to try it out soon. Thanks so much for all the ideas and encouragement.

Cheers,
Karen
View profile  Send private message
damian

Posts: 838
Posted: 05/05/2011, 7:31 PM

this is an idea i have been mulling over trying -

if your session timeout is 24mins you probably need to take some action around 20mins.
you only need to take action on forms. non forms dont need action - its ok if they get timed out - thats what the session timelimit is for

so on your form and table add one more field - call it ready - or whatever works for you. set it to required.

on your form add a checkbox for the field ready with the default being unchecked - in fact onload you need to uncheck it if this form data is regularly updated. make sure in the page that a value is required.

put a timer in the page onload that submits the form after 20mins. the form will submit and unless the checkbox is ticked the form *should* refresh the session data and return with all the currently enterred data still in the various fields.

user will get an error that *ready* is a required field and they can continue on their way.

i will hopefully get a chance to test over the weekend.

_________________
if you found this post useful take the time to help someone else.... :)
View profile  Send private message
karen

Posts: 99
Posted: 05/06/2011, 4:44 AM

Thanks Damian, that's a good idea too...better than my last resort idea. The only thing I find with this is that user's may find it unfriendly getting all the error messages although technically it is no different to renewing the session behind the scenes. The only difference is that it acts independently of the user's decision which can be a good thing if the user happen to be away from the computer :P

I've had a closer look at Jen's PHP/JS script. I'm assuming we don't have to do login script except setcookie? Where to put this? I don't think we'll need the query string 'expired' either. Do I put this somewhere in CCS generated login code? I don't want to break anything unnecessarily.

Then to handle the session timeout should be placed in the onload event of the page? Then I think the only other thing we need to do differently as datadoit has pointed out is in the jQuery UI Dialog where the button "Restart Session" is clicked. Here I can't reload the page. So that means I can't put the handle session timeout code in onload. Hmm, I'm going round in circles!

Maybe put that code in a separate page and have the "Restart Session" button call that page? Does that work?

Would appreciate any ideas at all. Thanks so much!

Cheers,
Karen
View profile  Send private message
Waspman

Posts: 948
Posted: 05/06/2011, 8:01 AM

I'd stick the code from the demo site in page which I'd embed in my main page (either iframe or jquery) Then when the session expires up pops the button and the refresh only refreshes the embedded page. Point the login button to your login page and you're away with the mixer ;-)


I do this all the time to keep sessions open. I just have the page refresh itself in the normal meta way.
_________________
http://www.waspmedia.co.uk
View profile  Send private message
karen

Posts: 99
Posted: 05/06/2011, 5:01 PM

Thanks for sharing your experience waspman. I know this should work since you've done it before.

When you say a page to embed, it's not an include page like you mentioned before, is it? Sorry, I'm not very experienced in such things. So in CCS terms, I'd build an include page with this code and include it in my main page within an iframe tag. Is that it?
View profile  Send private message
MichaelMcDonald

Posts: 640
Posted: 05/06/2011, 9:26 PM

this may assist:

http://forums.yessoftware.com/posts.php?post_id=110311
_________________
Central Coast, NSW, Australia.

View profile  Send private message
karen

Posts: 99
Posted: 05/06/2011, 10:24 PM

Hi Michael, thanks for this. I've actually bookmarked it just for reference before. It is something good to know but it is quite the opposite of what I want to do or rather the step before. This will implement the timeout while I want to renew the session to avoid the timeout for users who are taking a long time to fill in a form.

The thing that's good to know is how to find the time of the last action. But thereafter, I really need to have an action to renew the session.

Cheers,
Karen
View profile  Send private message
Waspman

Posts: 948
Posted: 05/07/2011, 1:40 AM

Quote karen:
Thanks for sharing your experience waspman. I know this should work since you've done it before.

When you say a page to embed, it's not an include page like you mentioned before, is it? Sorry, I'm not very experienced in such things. So in CCS terms, I'd build an include page with this code and include it in my main page within an iframe tag. Is that it?


Include the session check code in a normal page (not one that can be included) and use either iframe or jquery to embed the page in your master page. I would possibly embed the page in an included page like your header or footer if the session time out function is to operate across your site.

If you want me to make a dummy of it let me know...T
_________________
http://www.waspmedia.co.uk
View profile  Send private message
karen

Posts: 99
Posted: 05/07/2011, 4:11 AM

Thanks waspman. I think I'll take up your offer of a dummy example. That will get me started for sure. You're very kind :)

Cheers,
Karen
View profile  Send private message
Waspman

Posts: 948
Posted: 05/07/2011, 5:38 AM

OK, give me half an hour and I'll upload a link to the project files...T
_________________
http://www.waspmedia.co.uk
View profile  Send private message
Waspman

Posts: 948
Posted: 05/07/2011, 1:16 PM

this any good Karen?


http://www.waspmedia.co.uk/sessioncheck/login.php


It's from here...

http://philpalmieri.com/2009/09/jquery-session-auto-timeout-with-prompt/


I can send you the project, but you'll probably wont need it:)
_________________
http://www.waspmedia.co.uk
View profile  Send private message
karen

Posts: 99
Posted: 05/07/2011, 3:57 PM

Hey thanks, waspman. You're so quick! I'll look at it and let you know if I have any trouble. Pls be patient with me as I'm slow :) You can take a break for now :)
View profile  Send private message
karen

Posts: 99
Posted: 05/07/2011, 4:01 PM

I just quickly tested your demo, it's perfect! I would like the project pls if you don't mind. I'll pm you my email address? Thanks so much again!
View profile  Send private message
karen

Posts: 99
Posted: 05/11/2011, 7:06 PM

Just some update for everyone, especially waspman. Thanks waspman for helping me get started and pointing me in the right direction.

I've applied the jquery example from phil's and have gotten the basics working. Still have to iron out a few more things and maybe add stuff to it (we'll see). When I get it working well, I'll post it here so someone else can make use of it too.

Cheers,
Karen
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.