2014-08-27 84 views
0

我不知道为什么,但它在我的开发服务器上工作。我正在运行Apache2并使用PHP作为我的编程语言。服务器不完全相同,但非常相似/大多数情况下每个设置都是相同的。PHP重定向无法在生产服务器上工作

这是否与服务器上的PHP版本有关?

  • 生产运行:PHP版本5.4.27-1 + deb.sury.org〜精确+ 1

  • 开发运行:PHP版本5.4.32-2 + deb.sury.org 〜lucid + 1

或者也许我的代码中有东西我失踪了?

<?php 
$page = 'Home'; 
require_once('includes/config.php'); 
require_once('includes/auth.php'); 
require_once('includes/header.php'); 
?> 

<div id="content"> 
    <?php 
     if($loggedin){ 
      if(isset($customer)){ 
       header('Location: ftp.php'); 
       require_once('indexes/customers.php'); 
      } else if(isset($web_user)){ 
       if(checkperm($loggedin_id, 2)){header("Location: bulletin.php");} 
       if(checkperm($loggedin_id, 4)){ header("Location: signoff.php?dep=Workorders");} 
       require_once('indexes/employees.php'); 
      } 
     } else { 
      require_once('indexes/guest.php'); 
     } 
     //echo "<meta http-equiv='refresh' content='0;url=http://www.yoursite.com'>"; 
    ?> 
</div> 
<?php 
    require_once('includes/footer.php'); 
?> 

应用程序中的每个注册用户都设置了特定的权限和角色,以便他们可以访问应用程序的特定部分。

基本上,如果登录并且用户的“角色”设置为$ customer,他们将只能访问我们应用程序的FTP部分以下载/上传文件给我们。

如果登录并且用户的“角色”是$ web_user并且他们的checkperm(权限)是id:2(加工),那么在登录时将其重定向到公告页面。

如果登录并且用户的“角色”是$ web_user并且他们的checkperm(权限)是id:4(Manager),则将其重定向到工作单签发页面。

该代码与在开发服务器上运行的代码相同。

回答

3

你打电话:

header('Location: ftp.php'); 

你已经输出了一些内容之后。标题必须在任何输出之前发送!这包括HTML和PHP回声语句。

+0

啊是有道理的。我在php.ini中打开了output_buffering,并且暂时修复了它,至少在我写了一个解决方法之前。 – MikeOscarEcho 2014-08-27 14:05:27

1

使用下面的标题出口,但确保它之前发送任何输出。

 if(isset($customer)){ 
      header('Location: ftp.php'); 
      exit(); 
      /* Why do you have this line here? When redirect begins above then it will not be executed */ 
      require_once('indexes/customers.php'); 
     } 
相关问题