我正在用PHP进行开发,我需要为不同类型的用户更改页面,所以我这样做:
switch ($_SESSION['ruolo']) {
case 0:
header('Location: ./php/admin/homeAdmin.php');
exit();
break;
case 1:
header('Location: ./php/150ore/home150.php');
exit();
break;
case 2:
header('Location: ./php/150ore/home150.php');
exit();
break;
default:
break;
}
但是我只获得了一个白页...没有任何错误..
为什么?我哪里错了??
编辑:
我不喜欢默认情况,我检查了它..
这是我想要重定向的页面:
<?php require_once './php/doctype.php'; ?>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
PROVA!!!
</body>
</html>
最佳答案
为了调试此问题,需要执行以下操作:
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
switch ($_SESSION['ruolo']) {
case 0:
header('Location: ./php/admin/homeAdmin.php');
exit();
break;
case 1:
header('Location: ./php/150ore/home150.php');
exit();
break;
case 2:
header('Location: ./php/150ore/home150.php');
exit();
break;
default:
var_dump("I'm the default case!"); //If you get this, then your session variable is different to 0, 1 or 2.
break;
}
现在,在您的 homeAdmin.php
和 home150.php
页面中,在顶部添加:
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
看看错误是什么。
根据您的最新编辑,我可以看到您正在使用 require_once
,如果给定文件抛出错误,require
将停止执行,请尝试更改 require_once
到 include_once
以检查其是否有效,并共享 doctype.php
文件中的内容。另一件要尝试的事情如下:
<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
require_once './php/doctype.php';
?>
关于php - 为什么重定向 PHP 只得到白页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30876042/