help_lucky Posted March 10, 2010 Share Posted March 10, 2010 Hello Everyone, I am banging my head since morning. please help me.. I am not so good at php..i am in learning phase... My requirement was to generate a popup once you immediately login. windows.alert('please call') then the popup should come for every 2 hrs. Even though you navigate to different pages on the site..This should still come.. I have started something like this:-- 1. Calling this script on everypage. <script type="text/javascript"> alert_settimer(); </script> And the code in the script is function alert_settimer(){ time_stop=2*60*60*1000; if(time_stop > 0) { timer= setTimeout("alert_settimer(),window.focus();window.alert('Please call Originator');",time_stop ) } } It is able to give me a popup for every 2 hrs. But whenever the user reloads the page after 1 hr. The function is called again and the count starts from 0hrs again. OR for example if 20 mins already passed then if i am going to a new page then the function is called again and so the timer starts again. I am not getting any idea how to restrict it calling every time. OR send that 1 hr again to the function so that it starts from there. I tried some thing like setting the value in a session variable and then starting the counter from that value. But i am not successful. Please help me in solving this... Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted March 10, 2010 Share Posted March 10, 2010 Maybe you will get some response in javascript section, as it is related to javascript. Or a Mod can move it to that section. Quote Link to comment Share on other sites More sharing options...
jdorma0 Posted March 10, 2010 Share Posted March 10, 2010 This should do the job for you. It combines PHP, cookies and JavaScript. May not be the prettiest, but it gets the job done. Just call upon this function when the user logs in. You may need to customized it to get it right for your setting. <?php function cTimer(){ if(!isset($_COOKIE['LoginTimer'])) { setcookie ("LoginTimer", "TRUE", time() + 5); # This cookie set for to 5 seconds for testing [comment this when you're ready to use it] #setcookie ("LoginTimer", "TRUE", time() + 7200); # 2 hour cookie [remove the # symbol at the beginning of this line when you go live with the script] echo <<<JS <script language="JavaScript"><!-- window.alert('Please call'); //--></script> JS; } } cTimer(); //Call the cTimer function when you need the timer to be used ?> Let me know if that works for what you need. Joey Quote Link to comment Share on other sites More sharing options...
help_lucky Posted March 11, 2010 Author Share Posted March 11, 2010 Thanku very much for the time taken and for the response.. If that is the case then i will call the function cTimer(); on every page. Because whatever may be the page on the site i need to get a popup. So it will check whether the timer 2 hrs is done or not and then call this function. To give an alert message. But what if the user does not click/no action on the site for more than 2 hrs. Then the cookie expires and we will not get any alert message. If he clicks 1:50 mins after the cookie is set and then does not do anything thereof..we will not get any popup..Only if he is active after 2 hrs the cookie is set..then we get a popup... I need a popup for every 2 hrs even if the user is active or not on the site. Do let me know if anything is not clear from my side. Suggest me if any improvements can be done to meet the requirement. Quote Link to comment Share on other sites More sharing options...
help_lucky Posted March 11, 2010 Author Share Posted March 11, 2010 Hello, You gave me a good food to think..Thanku very much...The problem is solved...It is using cookies i did it... [quote]function timedCount() { if(c==0 && (getcookie("remind")!=null) && (getcookie("remind")!="") && getcookie("remind")!=1) { c = parseInt(getcookie("remind")); } c=c+1; document.getElementById('txt').value=c; document.cookie="remind"+ "=" +escape(c); if(c==30) { window.focus(); window.alert('Please call originator'); c=0; delete_cookie("remind"); } t=setTimeout("timedCount()",1000); } function doTimer() { if (!timer_is_on) { timer_is_on=1; timedCount(); } }[/quote] I created a invisible text field in the page where i am calling this function.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.