sql >> Base de Datos >  >> Database Tools >> phpMyAdmin

redirigir PHP usando un tiempo específico

Hacer uso de la date de PHP función para comprobar la hora/fecha actual. Para redirigir a otro archivo, solo use el encabezado header("Location: ..") función para hacer una redirección 302.

Aquí hay una muestra rápida de lo que pude entender de la descripción de sus requisitos:

<?php

    $redirectLocation = '';

    $dayOfWeek = date('l'); // A full textual representation of the day of the week
    $weekendDays = array('Saturday', 'Sunday'); // Array of weekend days
    $currentTime = (date('G').date('i'))*1; // Get current time in the form of numbers

    // If is weekend, redirect to weekend.php
    if(in_array( $dayOfWeek, $weekendDays )) {
        $redirectLocation = 'weekend.php';
    }

    // Else handle weekday day time (7.30 - 15.00)
    else if( $currentTime >= 730 && $currentTime <= 1500 ) {
        $redirectLocation = 'index1.php';
    }


    // Else handle weekday evening time
    else {
        $redirectLocation = 'night.php';
    }

    // Do the redirecting
    header("Location: ".$redirectLocation);
    exit();
    ?>