Pooya Soleimani Pooya Soleimani - 4 months ago 7
PHP Question

headers already sent by php ERROR :|

i have a problem of below code on php :(

<?php echo $_GET["u"];
$servername = "localhost";
$username = "******";
$password = "*****?";
$dbname = "*****";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$tt=$_GET["u"];
$sql = "SELECT url from code WHERE BINARY short="."'$tt'";
$result=$conn->query($sql);
$data=$result->fetch_assoc();
$url="Location: ".$data["url"];
header($url); /* Redirect browser */
exit();
?>


my problem on this line :(

header($url); /* Redirect browser */


$url variable is a link a get from database.!

Answer

Well, it's not lying. You have echo $_GET["u"]; at the top of your script.

There must be NO OUTPUT AT ALL before sending headers.