Reputation: 131
can someone tell me how to redirect to another page if ".php?date=" doesn't found. p.s i have distinct it and i think that is problem, so how to solve it? thanks before hand
<!--====================
left-block.php ======================-->
<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';
?>
Upvotes: 0
Views: 142
Reputation: 138287
<?php
if(!isset($_GET["date"])){
header("Location: http://newsite");
}
$date=$_GET["date"];
?>
As macroman pointed out, this only works if its at the very top of the page, before the first or echo.
Upvotes: 0
Reputation: 17637
You can't use headers to redirect after you've output anything to the page. Use something like this instead which echoes out javascript alternative:
else {
echo("<script>location.href = 'www.myurlhere.com';</script>");
}
Upvotes: 1