我正在重定向感謝PHP,但它根本不重定向(但使其他重定向)。php重定向,將不會重定向
下面是我實現的代碼:
<?php
session_start(); // pour pouvoir récupérer /creer desvariables de session
try
{
$bdd = new PDO('mysql:host=localhost;dbname=youf', 'root', 'root');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$redirection="command.php";
if (!isset($_SESSION['Login'])){ header('Location: connect.php'); } // Si pas de sessionactives, redirect
if (!isset($_SESSION['CommandId'])){
$long = strlen($_SESSION['Login']);
$table = $_SESSION['Login'][$long-2].$_SESSION['Login'][$long-1];
$zone = $_SESSION['Login'][$long-4].$_SESSION['Login'][$long-3];
$createCommand="INSERT INTO `youfood`.`command` (`Number`, `Date`, `isPaid`, `Table`, `Zone`, `Server`, `State`) VALUES (NULL, current_date, '0', '".$table."', '".$zone."', '".$_SESSION['NumberEmployee']."', '5');";
$bdd->query($createCommand);
$sqlCommandNumber=$bdd->query("SELECT * FROM `command` WHERE `Table` =".$table." AND `Zone` =".$zone." AND `State` =0 LIMIT 0 , 1");
$commandNumber="";
while ($data=$sqlCommandNumber->fetch()){
$commandNumber = $data['Number'];
}
$_SESSION['CommandId'] = $commandNumber ;
header('Location: actionValidateCommand.php');
$redirection="actionValidatedCommand.php";
} else {
foreach ($_SESSION['cart'] as $key => $value) {
if($value != 0){
$sql = "INSERT INTO `youfood`.`commanddishe` (`Number` ,`command` ,`Dishe` ,`Quantity`)VALUES (NULL, '".$_SESSION['CommandId']."', '".$key."', '".$value."')";
$bdd->query($sql);
$messagee = $messagee."<br />".$sql."<br />";
$_SESSION['cart'][$key] = 0 ;
}
}
header('Location: command.php');
$redirection="command.php";
}
?>
<!DOCTYPE html>
<html>
當我檢查不重定向頁面的HTML結果,我看到了標籤之前的空間。我不知道哪裏有空間,我知道這是錯誤的!
感謝幫助我:-)
嘗試使用:header('Location:path/here');出口; –
$ redirect = ...的目的是什麼?只需確保在header()將被調用之前在aol中沒有輸出到瀏覽器。 – Brian
標籤之前的空間?您可能在標題之前發送輸出。用'headers_sent'和'headers_list'檢查。 – hakre