How to make a Popup that only writes information in the cookie or anything and displays only once on the homepage of the site

1

I have an adult entertainment website and I need to make an 18 year term to enter the site before ... It will be displayed a screen confirming the age and such of the person so she can click ok if it is bigger. But the jquery code does not run any more for the user. can anybody help me? The desing and javascript part is 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>
    
asked by anonymous 04.07.2017 / 04:56

4 answers

1

Workaround 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>
    
04.07.2017 / 19:55
6

In the backend 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 JS like this:

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 route to be CI

  

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

On the front 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
}
?>
    
04.07.2017 / 05:20
1

I do not advise cookies for this it is better to use session as soon as the user logs in you start a session and create a variable where it is stored that it read the message then whenever it returns to index you check the variable in session to not display again the same message.

Read about it here:

Working with Sessions

will help mount the script

Hugs.

    
04.07.2017 / 05:11
1

You can try something simpler by using 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 accept or refuse buttons redirecting to wherever you want

    
05.07.2017 / 11:57