为什么这根本不起作用?他们没有空间没有输出,但我在configuaration.php之前放了重定向,它只保存我的数据库连接,这给了什么
<?php
require('configuration.php');
$voucher = $_SESSION['voucher'] ;
$result = mysql_query("SELECT used FROM codes where code='".$voucher."'");
$row =mysql_fetch_row($result);
if ( $row['used'] == "1" ) {
header('Location: invalid.php');
exit;
}
if ( $row['used'] == "0" ) {
header('Location: valid.php');
exit;
}
?>
configuration.php
可能有输出。(请记住,require/include在该时间点输出任何内容,因此任何空白或字符也将在该时间输出)。
出于好奇,如果你做以下事情,它会起作用吗:
<?php
ob_start();
require('configuration.php');
// your code with header(...);
ob_end_flush();
如果它与ob_start
/ob_end_flush
调用一起工作,那么configuration.php
正在输出一些东西。然而,需要注意的是:
- 永远不要将来自客户端的数据(通过
$_GET
/$_POST
/$_SESSION
)直接发送到SQL。尽管您可能正在设置会话数据,但根据数据的来源(例如cookie),开始在数据库中查找数据是非常容易的 Location
应该是完全限定的路径(http://mydomain.com/myfile.php
而不仅仅是myfile.php
)
您的代码只考虑$row['used']是0还是1。如果它根本不存在,就不会。你能var_dump$row看看你得到了什么吗?