S
S
Skrolea2017-03-27 12:03:10
PHP
Skrolea, 2017-03-27 12:03:10

How to make permission to view the page?

I didn’t quite understand how to google) Sorry. There is a site that needs to make a pop-up window when viewing certain articles "Are you 18 years old or not?" and, accordingly, either allow or not view the article (and if "no:, it should go somewhere). But not on the entire site. It still needs to be connected with Bitrix. In which direction to google?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2017-03-27
@Skrolea

<?
  session_start();
  if($_POST['is18years'] == 'yes' || $_POST['is18years'] == 'no') $_SESSION['is18years'] = $_POST['is18years'];
  if(isset($_SESSION['is18years'])) {
    if($_SESSION['is18years'] == 'no') {
      header("Location: /access_denied.html");
        	exit; 
    }
  }
?>

<?
  if(!isset($_SESSION['is18years'])):
?>
<div class="body_overhead">
  <div class="overhead_window">
  <div class="oh_wnd_header">
    <p>Доступ к сайту могут осуществлять только лица, достигшие возраста 18 лет</p>
    <p style="font-weight: bold;">Вам уже есть 18 лет?</p>
    <p>
      <span style="color: green" class="is18years yes18">ДА, мне уже есть 18 лет</span> | <span style="color: red" class="is18years no18">НЕТ, мне еще нет 18 лет</span>
    </p>
  </div>
  </div>
</div>
<style>
  .body_overhead {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 999999999;
  }
  .overhead_window {
    top: 10%;
    left: 30%;
    width: 40%;
    background: #fff;
    position: relative;
  }
  .oh_wnd_header {
    padding: 20px;
    color: #333;
    text-align: center;
  }
  .is18years {
  cursor: pointer;
  }
</style>
<?
  endif;
?>
<script>
  // проверка на 18 лет
  $('.is18years').click(function(){
    if($(this).hasClass('yes18') || $(this).hasClass('no18')) {
      var is18years = $(this).hasClass('yes18') ? 'yes' : 'no' 
      $.ajax({
  				type: "POST",
        	context: document.head,
 				data: { is18years: is18years },
        	success: function(){
        		if(is18years === 'yes') {
        			$('.body_overhead').hide()
        		} else {
        			document.location.href = '/access_denied.html'
        		}
       	}
      })	    
    }
  })
</script>

N
Nikolay, 2017-03-27
@nickolyashka

modal window + cookies

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question