Pregunta

I have googled it but I didn't found that type of code. I want a php code that will read a value that is the number of days that the access to a page will be approved.

For example, if today is the first opening of the page and the value of the days from the next opening will be 20, so, from today, we will add 20 days and then the page will be open again.

I better example is this one, we have a recruitment, the recruitment will be open for 2 days, and then, after those two days will be closed during 20, and then will open again(over and over again). But i want to define this two variables, the recruitment open time, and the time between the recruitment.

Other simpler function is that if I define a manual recruitment, it will open and when I close it, the recruitment will start counting 20 days from the day when I close it.

¿Fue útil?

Solución

I dont know any link, but ur code can be something like this. Please check the links, the functions are self-explanatory.

$lastRecDay = "2013-01-11"; // this will be coming from ur db


// create a date object
$date = new DateTime($lastRecDay);
//add 20 days to it
$date->add(new DateInterval('P10D')); // ur date is 20 from last day

//its 20 days+ since the posting
if( $date->format('U') <= strtotime('now'))
{
 // your code re-open goes here
}

Otros consejos

Ok, so it sounds like you need to monitor the following variables

Open date
Display days
Interval days
End date

Then you do it like this

create a page
enter the first open date
enter the days to be displayed
enter the days between closing and re-opening (interval)
enter the end date

then calculate if it is to be displayed by

if (today < enddate ) {
  if (today >= opendate) and (today <= opendate + displaydays)
    show
  else if (today > opendate + displaydays)
    opendate = today + interval
}

The question now is how do you store your data? I imagine this is easiest in a db, but you can probably do it inside a file as well.

Will expand on the instructions when I know your storage type.

In php, you can use date_add to add the date. And in mysql also there is date_add. That should solve your problem I guess.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top