Enable content after a date

Asked

Viewed 55 times

1

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

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

EX: Link 1 only releases after the day 24/03/2018

1 answer

2


In php you can check 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 will use Mysql, so here we 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>

registra_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 search for

Then when entering 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, logical that I will not leave here exactly everything you need, it is up to you to implement your logic. I hope I’ve helped

  • Thanks for the help Woton, but would be more or less like this, I am working with Wordpress I have a list with repeater which the user puts the name of each module of the course, however I can not leave all modules open, so I wanted to make the following logic - The user sets the release date by wordpress - If it is before the date the button is no click now if it is on the right date the button releases

  • @Lukascastro entedi, I do not understand much of wordpress, but the logic for me serious: create a database that saves the date that your user defined and on the page in question he looks for the field of my answer there "suadata" from the bank, I’ll modify the answer to show you with html and pure php, just a moment

  • Dude!! You and 10!!! Helped me a lot, Thanks spun smooth here!

  • @Lukascastro I’m glad you solved, so I would like you to mark the answer as accepted, so other people who have the same problem could solve it, vlw, have a great afternoon

Browser other questions tagged

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