I have one of the php site which I want to close or redirect a particular page from Saturday 9pm to Monday 6am.

the page contains a form and when they submit a form it directs to form.php.

So what i want to do is if some one access the page and uses the form then they have to be redirected back to the same form page and not be sending to form.php

I searched google a lot on this but no luck.

Right now I manually insert header location on form.php to redirect back them to form page. I am tired of doing this?

Can anyone help me on this please?

why dont you add a function to enable/disable the page?
then whenever you need to disable it you can just click a checkbox.
if you have an admin area you could add it there, or easily create a new page for the option.
then do an "if" command in php to check if the checkbox is enabled, if so then redirect to an error page, if not then goto the form

actually that does not help me much as the respective page is also used by API, hence i need to either disallow users stating the error message or just have it redirected to the same page so that unnecessary requests can be avoided to database.

so then create the checkbox to alter the outcome of the forms submission

ie. if checkbox is ticked redirect to same page, if not direct to form.php

I think am not making it clear, this particular page can also be accessed through HTTP API so checkbox option wont help me out here. :)

i dont see why not?
the checkbox will determin if a user can access that page. if the page is blocked then theres no way any type of browsing method will open it.

or you could add it to the forms submission so a redirect is set to your method.

something like this...

<?php 
$checkbox = the-location-of-the-checkbox-in-database;
if($checkbox == 1){
$outcome = 'form.php';
}else{
$outcome = 'the-same-page-location.php';
} ?>

<form method="post" action="<?php echo $outcome; ?>" name="form" >

more php is needed for the actual checkbox, but that code is something what would be needed to control your page.

the code what i got from internet and working fine as per below

<?php
/* Redirect browser */
if (date("H")<8) {
header("Location: ../index.php");
} else {
//do this
}
?>

But the problem is the above code works only from midnght to 8 am in the morning, but i want to block from saturday 9pm to monday 6am. so this between time is making it very critical for me to output the desired result. any help will be apprcieated

ok...what thats doing is blocking access from anything thats less than the hour value ("H") than 8 (<8)

changing the <8 will extend or decrease the time.
unfortunately im not sure how to set the desired time to start it...

you could try

<?php 
if(date("H")>21){

/* Redirect browser */
if (date("H")<8) {
header("Location: ../index.php");
} else {
//do this
}

}
?>

im not sure if thatl work but its worth a try

sorry...looking at that again it would be easier to do this....

/* Redirect browser */
if (date("H")>21) {
header("Location: ../index.php");
} else {
//do this
}

/* Redirect browser */
if (date("H")<6) {
header("Location: ../index.php");
} else {
//do this
}

is it possible to use header location after //do this because it gives an error as already header output would be there. what do you suggest?

how about this one, do you recommend this?

/* Redirect browser */
if (date("H")>21) {
header("Location: ../index.php");
} else if (date("H")<6) {
header("Location: ../index.php");
} else {
//do this
}

I also give it a try and update the same. Thanks for putting efforts and giving your time.

you can use the else if command instead, then only call the header in the final else command

i also noticed u need it for 3 days so youl need to define the date something like this...

$date = "2011-09-20 21:30:45";
$ts   = strtotime($date);
$date1 = "2011-09-23 21:30:45";
$tx   = strtotime($date1);


    /* Redirect browser */
    if (date('Y-m-d', $ts)>21) {
    header("Location: ../index.php");
    } elseif 

     (date('Y-m-d', $tx)<6) {
    header("Location: ../index.php");
    } else {
    //do this
    }

that might work

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.