我有下面的代码,它在localhost中运行良好,现在我已经在线上传了它,添加任何内容后页面重定向失败,它只显示第一个echo命令,没有其他内容。请帮忙。
<?php
session_start();
error_reporting(E_ALL ^ E_NOTICE);
echo "<span class='notification n-information'>Welcome to '".strtoupper($_SESSION['user'])."' Admin Panel</span>";
if($_SESSION['uid']==true){
if($_SESSION['roles']==2 or $_SESSION['roles']==1){
}elseif($_SESSION['roles']==3){
header('Location:../a/index.php?action=NOT Allowed');
}elseif($_SESSION['roles']==4){
header('Location:../b/index.php?action=NOT Allowed');
}elseif($_SESSION['roles']==5){
header('Location:../c/index.php?action=NOT Allowed');
}
}else{
header('Location:../index.php');
}
@require('quick.php');
@require('../conn/include.php');
$title=($_POST['title']);
$project=($_POST['project']);
$descrip=($_POST['description']);
if(isset($_REQUEST['add'])) {
$add="Insert into projects(project_name,title,details)VALUE('$project','$title','$descrip')";
//echo "$add";
$addquery=mysql_query($add);
header('location:Projects.php');
exit();
}
?>
我的表单操作=",因为我正在将其重定向到同一页面
尝试将Projects.php
重命名为projects.php
,因为如果您使用的是linux server
,那么这些服务器在文件名中是case sensitive
。。并尝试从required
中删除@
。。
Location
标头必须在任何其他内容(例如span
标签)之前回显。否则,您的浏览器将忽略标题,并在脚本终止前显示您已经回显的内容以及脚本回显的其他内容。
此外:当满足发送重定向请求的条件时,继续执行并用exit;
或die()
语句结束脚本的其余执行。
这应该有效:
if($_SESSION['uid']==true){
if ($_SESSION['roles'] != 1 and $_SESSION['roles'] != 2)
{
switch($_SESSION['roles'])
{
case 3:
$url = "../a/index.php?action=NOT Allowed";
break;
case 4:
$url = "../b/index.php?action=NOT Allowed";
break;
case 5:
$url = "../c/index.php?action=NOT Allowed";
break;
default:
$url = "../index.php";
}
header('Location:'.$url);
die();
}
}
echo "<span class='notification n-information'>Welcome to '".strtoupper($_SESSION['user'])."' Admin Panel</span>";