如果找不到或不存在date.php?date = *,如何重定向

时间:2016-08-03 14:26:37

标签: php html mysql redirect mysqli

如果找不到“.php?date =”,有人可以告诉我如何重定向到另一个页面。 p.s我有它的区别,我认为这是问题所以如何解决? 先谢谢

<!--====================

左block.php     ====================== - &GT;

<ul class="side-block">
                <li><a href="#">არქივი</a></li>
                <?php 
             $archive = mysqli_query($db,"SELECT DISTINCT left(date,7) as month FROM blog ORDER BY month DESC , id DESC LIMIT 6");
             while($myrow = mysqli_fetch_array($archive)){
                 printf('<li><a href="date.php?date=%s" class="custom">%s</a></li>',$myrow["month"],$myrow["month"]);
                }
?>
            </ul>
<!--
===============================================
date.php
===============================================
-->

<?php 
     include 'bd/blocks/bd.php'; 
     $result = mysqli_query($db,"SELECT keywords,description,author FROM page WHERE page='blog'");
     $myrow = mysqli_fetch_array($result);
if(isset($_GET['date']) && !empty($_GET['date'])){
    $date = $_GET['date'];
}
elseif (!isset($_GET['date']) && empty($_GET['date'])) {
    header("Location: index.php");
    exit;
}
else{
    header("Location: index.php");
    exit;
}
$date= "$date";
$dates=substr($date,0,7);
$result2 = mysqli_query($db,"SELECT date FROM blog WHERE date='$dates' ");
$myrow2=mysqli_fetch_array($result2);
echo mysqli_num_rows($result2);
if(!mysqli_num_rows($result2)){
 header("Location: index.php");
    exit;
}
     $date_title=$date;
     $date_begin =$date;
     $date++;
     $date_end=$date;
     $date_begin=$date_begin.'-00';
     $date_end=$date_end.'-00';
 ?>

2 个答案:

答案 0 :(得分:1)

在您向网页输出任何内容后,您无法使用标题重定向。使用类似这样的东西代替javascript替代:

else {
    echo("<script>location.href = 'www.myurlhere.com';</script>");
}

答案 1 :(得分:0)

<?php 
if(!isset($_GET["date"])){
header("Location: http://newsite");
}
$date=$_GET["date"];
?>

正如macroman指出的那样,只有当它位于页面顶部,第一个或回声之前时才有效。