douhu5837 2012-07-23 08:25
浏览 43
已采纳

index.php没有显示。 而是显示错误页面

i have a page with 4 links namely 1st.php, 2nd.php, 3rd.php, and 4th.php. my index.php displays the 3rd.php as default. i also created a 404.php (error page) so that when a user edits the URL it will not redirect to the index.php, instead it will display the error page. the problem is when i open my index.php page, it displays the error page instead. need help. this is my code:

 <?php 

  $quarters = array('Q1', 'Q2', 'Q3', 'Q4');
        $quarter = 'Q3';

        if(isset($_GET['quarter']) && in_array($_GET['quarter'], $quarters)) {
          $quarter = $_GET['quarter'];  
        }

        switch($quarter) {
          case 'Q1' :
            $quarter = 'firstq2012.php';
          break;
          case 'Q2' :
            $quarter = 'secondq2012.php';
          break;
          case 'Q3' :
            $quarter = 'thirdq2012.php';
          break;
          case 'Q4' :
            $quarter = 'fourthq2012.php';
          break;
        }

    $pages = array('Q1','Q2','Q3','Q4');
    if (in_array($_GET['quarter'], $pages)){            
                    include_once $quarter;  
 }
 else {
 header('Location: 404.php');
  }
?>
  • 写回答

2条回答 默认 最新

  • donglun1020 2012-07-23 08:44
    关注

    Your code can be cleaned up a lot.

    Try using this intead:

    <?php 
    $quarters = array('Q1' => 'firstq2012.php', 'Q2' => 'secondq2012.php', 'Q3' => 'thirdq2012.php', 'Q4' => 'fourthq2012.php');
    if(isset($_GET['quarter'])) {
        if(in_array($_GET['quarter'], array_keys($quarters))) {
            include_once $quarters[$_GET['quarter']];
        } else {
            header('Location: 404.php');
        }
    } else {
        include_once $quarters['Q3'];
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧