dongzhuang2030 2013-09-27 17:02
浏览 29

包含PHP的目录

I forgot to ask this in my question here: PHP Dynamic Include Help on Index.php?

How do I make it so directories are used with php includes? For example. I want to rename page2 to rules, then put the rules.php file into a folder called /rules/, so its now /rules/rules.php

As a result, the new url would be something like index.php?category=rules&id=rules

Here is the new code.

    <?php
    $page='';
    if (isset($_GET['id'])){
    $page = $_GET['id'];
    }
    $pageArray = array('index','css-pub1','page2','page3','page4','page5','page6');
    $inArray = in_array($page, $pageArray);
    if ($inArray == true) {
    include(''. $page .'.php');
    } 
    else {
    include('main.php');
    }
    ?>
  • 写回答

1条回答 默认 最新

  • douliexu5623 2013-09-28 00:18
    关注

    this should do it, but to make it more secure you hace to check the page-category pair existance before the include (and maybe you should use include_once instead)

    <?php
    $page='';
    if (isset($_GET['id'])){
        $page = $_GET['id'];
    }
    if (isset($_GET['category'])){
        $category = $_GET['category'];
    }
    $pageArray = array('index','css-pub1','page2','page3','page4','page5','page6');
    $categoryArray = array('cat1','cat2','cat32');
    
    $inArrayPage = in_array($page, $pageArray);
    $inArrayCategory = in_array($category, $categoryArray);
    if ($inArray && $inArrayCategory) {
        include(''. $page .'/'.$category.'.php');
    } 
    else {
        include('main.php');
    }
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)