Abhijit Kumbhar Abhijit Kumbhar - 4 months ago 35
PHP Question

Using godaddy how to use header("Location:URL")

On my localhost this page redirection working properly but when I setup my project on Godaddy hosting site it doesn't redirect to page it actually displaying same page!
My code is as below:

<?
session_start();
include_once('connection.php');

$news_id=$_GET["id"];
$m_id=$_GET["m_id"];
$category =$_GET["category"];

$res=mysqli_query($con,"delete from marathi where id=$news_id");
if($res<=0)
{
$_SESSION["MSG"]="News not deleted, Try Again";
header("Location: m_news.php?id=".$m_id."&name=".$category);
}
else
{
$_SESSION["MSG"]="News deleted";
header("Location: m_news.php?id=".$m_id."&name=".$category);
}
?>


When I use godaddy this line is not working ..


header("Location: m_news.php?id=".$m_id."&name=".$category);

kb. kb.
Answer

Always add a die() call after issuing Location headers.

The HTTP response must be terminated without any body data for browsers to properly interpret the redirect headers, if you just run your header() and let the PHP script continue there is no guarantee that the body of the response will be empty and if it isn't the redirect will not work.

header("Location: m_news.php?id=".$m_id."&name=".$category);
die(); // Stop further execution and prevent any accidental output.