我正在重定向感谢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