Enable content after a date

1

Good afternoon, I'm new here and also in this universe of programming

I needed to make a link on my site available only after a date.

EX: Link 1 only releases after 3/24/2018

    
asked by anonymous 15.03.2018 / 14:18

1 answer

2

In php you can do the verification when opening the page:

<?php

//Data atual
$date = date('Y-m-d');

if($date >= suadata){
// não faz nada;
}else{

  //O die vai fazer o script morrer se a data for menor que a esperada
  die('Site não disponível, volte em "Sua data"');
}
?>

//Seu site dps
<html>...

// You want the user to set a date and then from there the page will see if the current date is in agreement, in the example I'll use Mysql, so let's go:

<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="utf-8">
<title>For Business</title>

</head>
<body>

      <form method="POST" action="php/registra_data_no_db.php">
          //Procure algo para formatar essa data
          <input type="text" id="data" required="true">

        <button type="submit" >Cadastrar</button>

      </form>

 </body>
</html>

log_data_no_db.php:

  <?php

  $mysqli = new mysqli("host", "user", "password", "db");

  $data = $_POST['data'];

  $mysqli->query("INSERT INTO suatabela VALUES (NULL,'id_da_pagina','$data')");

  ?>

On your page you use the bank id to know which page to look for

Then when you enter the page you check:

  <?php

   $mysqli = new mysqli("host","user","password", "db");

   $date = date('Y-m-d');
   if($mysqli->query("SELECT * FROM suatabela where id_da_pagina='identificacao_da_sua_pagina' AND data >='$date'")){
   //Se existe então é verdadeiro, ou seja, não faz nada, só continua
   }else{
   //Caso não exista, o die morre o script
       die('Data indisponível');
   }


   //Sua página
   <html>....

Remember, this example is very generic, it is only for you to have an idea of how to do, of course I will not leave here exactly everything you need, it is up to you to implement your logic. I hope I have helped

    
15.03.2018 / 14:26