使用php进行页面导航

使用php进行页面导航,php,redirect,navigation,hyperlink,Php,Redirect,Navigation,Hyperlink,我正在尝试创建一个动态网站,index.php在网站的内容区域包含以下代码: <?PHP // if undefined then define if(!$od || $od == ""){ $od = "news"; } // check if exists prep $link = 'incs'."/".$od.$ext; flush(); $fp = fopen($link, "r"); // check if inclusion file not exists th

我正在尝试创建一个动态网站,index.php在网站的内容区域包含以下代码:

<?PHP

// if undefined then define
 if(!$od || $od == ""){
 $od = "news";
 }
// check if exists prep
 $link = 'incs'."/".$od.$ext;
 flush();
 $fp = fopen($link, "r");

// check if inclusion file not exists then return error
 if (!$fp) {
 echo "An error has ocurred while processing your request. The file linked as ?od=".$od." does not appear to exist.";
 }

// if exists then return parse
 else { 
 fclose($fp);
 include 'incs'."/".$od.$ext;
 }

echo '</body>'."\n";
echo '</html>'."\n";

?>

我在整个网站上也有各种链接,比如注册、登录等。 这些链接指向诸如“od=注册”、“od=登录”等页面

网站将为我提取默认文件、新闻,并在网站的“我的内容”部分显示该文件,但当我单击“注册”时,地址栏中的url确实更改为/?od=注册,但默认新闻仍保留在“内容”部分,上述代码中是否有错误?还是我错过了什么


p.S.
$ext
在我的配置文件中定义为
inc.php
,它包含在索引页的顶部。

除了这是非常不安全的事实之外,您正在发出GET请求,通过
$\u GET
数组ie
$od=$\u GET['od']访问变量

我认为您需要使用$\u GET['od']或$\u REQUEST['od']定义$od

$od = $_GET['od'];
// if undefined then define
 if(!$od || $od == ""){
 $od = "news";

我会通过检查$op是否为inarray()来确保它的安全性;示例如果(在_数组($op,$pagenames)){//perform inclusion}EDIT:syntax errorYep,恶意用户几乎可以通过fopen确定服务器上有哪些文件,例如:Example.com/?op=../index这样做可能会返回目录在执行包含之前,我需要设置$op和$pagenames什么?这是否意味着我需要彻底摆脱fopen??