How to make a Popup that only records information on the cookie or anything and displays only once on the website homepage

Asked

Viewed 629 times

1

I have an adult entertainment site and I need to do an 18-year term to get on the site before... A screen will be displayed confirming the age and such of the person to click ok if it is bigger. But the jquery code no longer runs for the user. Can someone help me? The desing and javascript part are already ready:

JS:

jQuery(document).ready(function(){
    jQuery('a.accept_legal_majority').click(function(){
        jQuery('#cp_overlay').remove();
        jQuery('#legal_majority').remove();
        jQuery.get('https://www.site.com.br/salvar', function(data){
            //console.log(data);
        });
    });
});

HTML:

<div id="cp_overlay" style="opacity:0.9;"></div>
<div id="legal_majority">
  <div class="legal_majority_content">
    <div class="header_warning">


      <div class="title txt-center">
        <h1 style="font-size:22px;"><span class="color-rejected">Aviso: </span>Este website é apenas para adultos!</h1>
      </div>
    </div>
    <div class="terms">
      <a class="bg-hover-free btn_submit accept_legal_majority">Eu aceito</a>
    </div>
    <a href="http://www.google.com" class="legal_majority_out txt-center btn-edit">Não Tenho 18 anos, Desejo Sair</a>
  </div>
</div>
  • 1

    What is the back-end language? I would recommend sessions.

  • Codeigniter, but in this case I can use Php or even simple html

  • 1

    What version of Codeigniter? 3?

  • Yes, the 3. Exactly,

4 answers

6

In the back end you can use session_start(); and define a variable, something like:

accept php.

<?php

session_start();

$_SESSION['aceito'] = 1;

If it’s Codeigniter 3:

 $this->load->library('session');
 $this->session->aceito = 1;

In the JS so:

jQuery(document).ready(function(){
    jQuery('a.accept_legal_majority').click(function(){
        jQuery('#cp_overlay').remove();
        jQuery('#legal_majority').remove();
        jQuery.get('aceitar.php', function(data){
            //console.log(data);
        });
    });
});

Or set the random route is CI

It is important to note that Session should come before any echo, print, or html, this is because Session uses headers in the HTTP response

On the home page do this (short version):

<?php $this->load->library('session'); ?>
<html>

...

<?php
if (!$this->session->aceito) {
?>
<div id="cp_overlay" style="opacity:0.9;"></div>
<div id="legal_majority">
    <div class="legal_majority_content">
        <div class="header_warning">
            <figure class="logo">

            </figure>

            <div class="title txt-center">
                <h1 style="font-size:22px;"><span class="color-rejected">Aviso: </span>Este website é apenas para adultos!</h1>
            </div>
        </div>
        <div class="terms">
            <p class="txt-center">Por favor leia o seguinte texto antes de entrar no site lascivacam.com:</p>
            <div class="contract">
                <p style="color:#000;">
    Este website contém cont ...
    .... enho 18 anos, Desejo Sair</a>
    </div>
</div>
<?php
}
?>

If the popup page is not the main one you can opt for a redirect:

<?php

$this->load->library('session');
if (!$this->session->aceito) {
?>

<div id="cp_overlay" style="opacity:0.9;"></div>
...
</div>
<?php
} else {
?>
<script>window.location="paginaprincipaldepoisdoaceitar.php";</script>
<?php
}
?>
  • 1

    That William certificate !! = P

  • the popup page and the main one, but like it is not able to recover the Session, to know the q was recorded.

  • 1

    @Brunoroberto I will test here and as soon as I can warn you.

  • And because my IC is a bit complex, it is not as standard as generally and Ci ... it has subfolders with views for each type of application.

  • Cokiee n would be better n let it expire pro user ... I think q would be much better.

  • @Brunoroberto Session has to come before any echo, print or html, it has to stay on top of everything, if it doesn’t work, Obs: cookies expire too and if there is no expiration date they are removed when the browser is closed, which is the same thing as Session.

  • in the case as I did, it’s working the right way that I needed to.

  • @Brunoroberto I’m not talking about that, I’m talking about the general behavior, it’s not because it seems to work that it won’t fail, PS: The Septssion didn’t work for you because the $this->load->library('session') should be at the top of the document, before echo, print and the <html>

  • A yes, sorry hahaha!

  • Was it you who denied @Brunoroberto ? Is there a reason for this?

  • LocalStorage it wouldn’t be easier?

  • 1

    @Maxrogério between easy and difficult depends on the intimacy of the staff with front-end and back-end, he reported that uses CI3 I gave an example that is in an environment that he is accustomed, any way is easy for those who are accustomed to an environment.

Show 7 more comments

1


Solution for this application :

<script type="text/javascript">
   function setCookie(name, value, days) {
       if (days) {
           var date = new Date();
           date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
           var expires = "; expires=" + date.toGMTString();
       } else var expires = "";
       document.cookie = name + "=" + value + expires + "; path=/";
   }

   function getCookie(name) {
       var nameEQ = name + "=";
       var ca = document.cookie.split(';');
       for (var i = 0; i < ca.length; i++) {
           var c = ca[i];
           while (c.charAt(0) == ' ') c = c.substring(1, c.length);
           if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
       }
       return null;
   }

   $(document).ready(function () {

       var box = getCookie('janela_modal');

       if (box == null) {
           launchWindow('#dialog1');
           $('.window .close').click(function (e) {
               e.preventDefault();
               $('#mask').hide();
               $('.window').hide();
           });
           setCookie('janela_modal', 'visitou', 1);
       }
   });

   function launchWindow(id) {
       var maskHeight = $(document).height();
       var maskWidth = $(window).width();
       $('#mask').css({
           'width': maskWidth,
           'height': maskHeight
       });
       $('#mask').fadeIn(0);
       $('#mask').fadeTo("fast", 0.8);
       var winH = $(window).height();
       var winW = $(window).width();
       $(id).css('top', winH / 2 - $(id).height());
       $(id).css('left', winW / 2 - $(id).width() / 2);
       $(id).fadeIn(0);
   }
</script>
</head>


<div id="cp_overlay" style="opacity:0.9;"></div>
<div id="legal_majority">
  <div class="legal_majority_content">
    <div class="header_warning">


      <div class="title txt-center">
        <h1 style="font-size:22px;"><span class="color-rejected">Aviso: </span>Este website é apenas para adultos!</h1>
      </div>
    </div>
    <div class="terms">
      <a class="bg-hover-free btn_submit accept_legal_majority">Eu aceito</a>
    </div>
    <a href="http://www.google.com" class="legal_majority_out txt-center btn-edit">Não Tenho 18 anos, Desejo Sair</a>
  </div>
</div>
  • 1

    Show Bruno Roberto Congratulations!

  • Thanks @Rafaelsalomão

1

I do not advise cookies so it is better to use session as soon as the user enters you starts a session and creates a variable where it is stored that he read the message then whenever he returns the index you check the variable in session not to display again the same message.

Take a look at this :

Working with Sessions

will help to assemble the script

Hugs.

  • 2

    This would look better as a comment.

  • I answered your question above.

  • I think q have it as Session would not be a good idea being that my code and worked on codeigniter () it already has Sesssions, and the button actually and a link... and not a button with Submit

  • 1

    not all browsers use cookies and many of them have cookies disabled so for this framework will repeat so I advised session. If there is already a session defined in your script just add a session variable to mount what I explained above!

  • 1

    Where did you get that you do not accept cookies? Session is cookie, as you would not accept? I think you are making confusion, what some browsers do not accept is the interaction with HTTPS control of cookies or the access in the client-side and this depends a lot, but in the back-end does not have this no.

  • 1

    Just the user disable the cookies and ready does not work anymore. For this cookie is a bore! I use memcached to save data like this! In addition there are few browsers that do not have cookie support. I cite native browsers from old cell phones and televisions. To read about Session without cookies you can follow this : https://wiki.locaweb.com.br/pt-br/Session_no_Php_sem_a_utiliza%C3%A7%C3%A3o_de_cookies

  • 1

    Yes, but if disabling cookies or the browser does not support the session would not work either, the only way to resolve it would be by using sessionStorage or localStorage or even IP-based which might be even worse. If the person’s browser does not work with cookies the user would not be able to access sites such as facebook ;)

  • 1

    REFERENCE http://www.php.net/manual/en/intro.session.php "A visitor accessing your website receives a unique identifier, the so-called session id. This is saved in a user-side cookie or propagated via URL." However, Php also provides alternative ways (id propagated via URL) to save the session ID without the use of cookies. = P

  • 1

    @Rafaelsalomão seems almost a good one, but if the visitor goes out and comes back it will not work, you understand?

  • 2

    Ahh yes you’re right! Certissímo as in your post!

  • In case the visitor leaves and return is unique , no problem, now n can and only work for one each user and responsible for your pc.

  • I managed to solve with this problem here I go of the answer there above.

Show 7 more comments

1

You can try something simpler using a Modal in your view and the following code in your Controller

$this->session->set_flashdata('alert', 'Sua mensagem');

view:

<h3 style="color:red;"><?php echo $this->session->flashdata('alert');?></h3>

and add the buttons to accept or refuse redirecting to where you want

Browser other questions tagged

You are not signed in. Login or sign up in order to post.