0

I am trying to achieve like below.

I have a website that I am building here http://ahsanurrahman.com/myprojects/cms/wp/chris-aa/pr1/

I want to force visitor to login or register using a popup that comes out automatically after 5 minutes or like that and remains forever until they login or register. To achieve this I have done like below

<?php
if ( ( is_single() || is_front_page() || is_page() ) 
       && !is_page('login') && !is_page('register') && !is_user_logged_in()){

    echo'<div class="overlay-bg">
</div>
<div class="overlay-content popup3">
    <h1>You must login or Register to view this site.</h1>
</div>';
} 

?>

To show that popup I am using java-script that shows after 1 minutes if the user not logedin. But if they refresh the page the popup gone and come after 1 minutes again.

So what I want to do is that I want to show the popup to each visitor after 1 minutes but want to keep that popup remains there until they login or register forever even they refresh it.

Thanks

  • You should look into [localStorage](http://www.w3schools.com/html/html5_webstorage.asp). Basically what you need to do is check if the user is new or not. That can be achieved by setting a value in the client's localStorage the first time they visit the site. Then, on every load, you can first check if that variable exists and decide when to show the popup. Cookies are also an option, but for this case I would say localStorage is a good way to go. Without relying on these, in pure javascript you won't be able to know if the user was there before, everything is reset on every page load. – 1cgonza Oct 28 '15 at 07:10
  • How can I set that in my code plz. plesae mention that if I have to set it in javascript or php – Md. Amanur Rahman Oct 28 '15 at 09:26
  • That will go on your javascript, follow the link on my previous comment to get started. If you decide to use localStorage, give it a go, if it does not work, update your question and I bet you can get the help you need. – 1cgonza Oct 28 '15 at 10:26
  • Actually this is what I need exactly http://stackoverflow.com/questions/33385670/show-popup-and-reset-timer-on-refresh/33385961?noredirect=1#comment54566630_33385961 – Md. Amanur Rahman Oct 28 '15 at 11:07

1 Answers1

0

I got the answer from my self with the help of my friend .The cookie should set like below

<?php
setcookie("visited",true);

if(!empty($_COOKIE['visited']) && $_COOKIE['visited'] == true)
 $popup_time = 0;
 else
 $popup_time = 60000; 
?>

Here $popup_time variable is set to the function javascript code like below

setTimeout(function() {
        // Show popup3 after 2 seconds
        showPopup(3);
    }, <?php echo $popup_time?>);

And that's it :) . I am frustrated that no one given me a right way here.

Anyway thanks