第二次PHP包含调用失败

时间:2013-12-01 21:22:00

标签: php

第二次调用包含文件时。我的页面崩溃了。这个包含文件中有什么内容可以阻止它在标题区域中调用一次,在页脚区域中调用一次吗?

<div class="module context-nav">
<?php function findInclude () {
$directory = $_SERVER["REQUEST_URI"];
$directory=substr($directory,9);
$directories = explode("/",$directory);
switch($directories[0]){
case 'students':
switch($directories[1]) {
case 'undergrad':
include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/students.php");
break;
case 'graduate':
include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/students.php");
break;
case 'society':
include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/students.php");
break;
case '4yearbsn':
include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/bsn.php");
break;
case 'postdegreebsn':
include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/postdegbsn.php");
break;
case 'postregbsn':
include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/postregbsn.php");
break;
case 'neps':
include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/neps.php");
break;
case 'master':
include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/masters.php");
break;
case 'postgradnp':
include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/postNP.php");
break;
case 'phd':
include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/phd.php");
break;
default:
include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/students.php");
break;
}
break;
case 'intranet':
    switch($directories[1]) {
case 'research':
include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/intranetresearch.php");
break;
case 'elearning':
include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/intranetelearning.php");
break;
default:
include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/intranet.php");
break;
}
break;


    case 'programs':
    switch($directories[1]) {
case 'neps':
include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/programs.php");
break;
case 'postreg':
include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/programs.php");
break;
case 'masters':
include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/programs.php");
break;
case 'practitioner':
include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/programs.php");
break;
case 'phd':
include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/programs.php");
break;
default:
include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/programs.php");
break;
}
break;
    case 'alumni':
      include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/alumni.php");
      break;
    case 'college':
    switch($directories[1]) 
{
case 'deansblog':
include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/college_deansblog.php");
break;
default:
include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/college.php");
break;
}
break;
    case 'research':
      include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/research.php");
   break;
    case 'cedn':
      include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/cne.php");
      break;
    case 'predeparture':
   switch($directories[1]) {
     case 'transcultural':
   include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/transcultural.php");
   break;



     default:
          include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/predeparture.php");
          break;
   }
   break;
    case 'custodycaring':
      include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/custodycaring.php");
      break;
   case 'predeparture':
      include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/internationalexperience.php");
      break;
    case 'aboriginal':
      include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/napm.php");
      break;
case 'rbcnursesforkids':
      include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/innovation.php");
      break;
    case 'casnie':
      include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/innovation.php");
      break;
 case 'elearning':
      include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/elearning.php");
      break;
 case 'virtuallab':
      include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/virtuallab.php");
      break;   
 case 'news':
      include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/college.php");
      break;
 case 'pandemic':
      include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/pandemic.php");
      break;
    case 'ihfc':
      include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/ihfc.php");
      break;
    case '75th':
      include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/75th.php");
      break;
case 'stylesheet':
      include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/stylesheet.php");
      break;   
    default:
        include  ($_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/blank.php");
break;
}
}
?>

<?php findInclude(); ?>
</div>

2 个答案:

答案 0 :(得分:3)

尝试使用:

include_once();

有关详细信息,请参阅PHP人员。

答案 1 :(得分:1)

始终使用include_once优先选择绝对路径:

差异是 include_once 只是检查脚本是否先前已包含在内。如果是,那么第二个包含将被忽略。

include_once $_SERVER['DOCUMENT_ROOT']."/nursing/includes/leftnavigation/students.php";

要进行严格检查,请使用 require_once ,它会执行相同的操作,除非它为您提供致命错误(停止执行脚本)而不是警告。