1
4

3 回答 3

5
if( isset( $_GET['go'] ) ){
 $go = $_GET['go'];
}else{
 $go = 8;
}
于 2013-01-07T23:48:39.620 回答
1

John 发布了一个有用的解决方案和设置代码的好方法;但我也认为在修复该错误后,您可能会通过搜索由以下原因引起的错误目录来获得另一个错误:

if(is_file("page/$go.php")) include "page/$go.php";

更正将是:

if(is_file("page/" . $go . ".php")) include "page/" . $go . ".php"; // would go to page/32.php

如果您不将变量与字符串分开,它将试图寻找错误的链接。

于 2013-01-07T23:55:34.797 回答
0

您需要isset($_GET['go'])在尝试访问它之前进行检查。下面的代码解决了这个问题。

<?php
if( isset($_GET['go']) && !empty($go) ) {
    $go = $_GET['go'];
    if(is_file("page/$go.php")) include "page/$go.php";
    else echo "<br />Nie ma takiej strony.";
}
else include "page/8.php";
于 2013-01-08T00:09:36.910 回答