Php codeigniter:如何处理错误url中不必要的结果?

Php codeigniter:如何处理错误url中不必要的结果?,php,codeigniter,Php,Codeigniter,我是一名新的CI开发人员,在一个网站上处理安全问题 我有一个类似的url: http://myweburl/Everything/gov/2 哪个“2”表示要查询数据库的参数 我的问题是: 如果有人浏览以下url: http://myweburl/Everything/gov/2/order.txt 实际上url中没有任何内容,但是..他将得到一个空的结果页。(回复200 OK) 这不是我想要的。 我希望他会得到一个404错误或其他东西来告诉用户url中没有任何内容 有谁能给我一些如何实现我

我是一名新的CI开发人员,在一个网站上处理安全问题

我有一个类似的url:

http://myweburl/Everything/gov/2
哪个“2”表示要查询数据库的参数

我的问题是: 如果有人浏览以下url:

http://myweburl/Everything/gov/2/order.txt
实际上url中没有任何内容,但是..他将得到一个空的结果页。(回复200 OK)

这不是我想要的。 我希望他会得到一个404错误或其他东西来告诉用户url中没有任何内容

有谁能给我一些如何实现我的目标的线索吗?
非常感谢

基本上,只有当URL中表示查询中参数的URI段的数目正确时,才需要显示有效页面

在调用任何其他方法之前,您应该检查
URI段的数量作为预处理。通过这种方式,您可以确保URL中实际上只有一个段

如果您发现您的
URL
中存在超过3个段,请使用CodeIgniter提供的方便功能相应地处理这种情况

您可以检查URL中的段数是否正确,如果它不是您想要的,则调用
show_404()
方法

在您发布的示例URL中:
http://myweburl/Everything/gov/2/order.txt
,实际上有4段

    // from the docs http://codeigniter.com/user_guide/libraries/uri.html

     $total_segments = $this->uri->total_segments();

    // 3 segments would be the max if this is your url:
    // http://myweburl/Everything/gov/2/order.txt (this url contains 4 segments)
    //                 ^controller/function/uri_segment
    // this means that there are 3 segments in your URL
    // you don't want to have more than 3, so check for that
    // with the total_segments() function

     if($total_segments > 3)

     {
           $valid = false;
           show_404();

     }

     else 

     {

          $valid = true;

     }

     if($valid) 

     {

     // process data as usual

     }

基本上,您只希望在URL中表示查询中参数的URI段的数目正确时显示有效页面

在调用任何其他方法之前,您应该检查
URI段的数量作为预处理。通过这种方式,您可以确保URL中实际上只有一个段

如果您发现您的
URL
中存在超过3个段,请使用CodeIgniter提供的方便功能相应地处理这种情况

您可以检查URL中的段数是否正确,如果它不是您想要的,则调用
show_404()
方法

在您发布的示例URL中:
http://myweburl/Everything/gov/2/order.txt
,实际上有4段

    // from the docs http://codeigniter.com/user_guide/libraries/uri.html

     $total_segments = $this->uri->total_segments();

    // 3 segments would be the max if this is your url:
    // http://myweburl/Everything/gov/2/order.txt (this url contains 4 segments)
    //                 ^controller/function/uri_segment
    // this means that there are 3 segments in your URL
    // you don't want to have more than 3, so check for that
    // with the total_segments() function

     if($total_segments > 3)

     {
           $valid = false;
           show_404();

     }

     else 

     {

          $valid = true;

     }

     if($valid) 

     {

     // process data as usual

     }

哪一个是你的控制器<代码>一切
?事实上,我知道了。您的控制器是
一切
,您的功能是
gov
2
是您的部分。对不起,我没有很好地解释我的问题。一切->控制器管理->功能2->参数段一切正常。我的回答应该对你有帮助。(我希望)哪一个是您的控制器<代码>一切
?事实上,我知道了。您的控制器是
一切
,您的功能是
gov
2
是您的部分。对不起,我没有很好地解释我的问题。一切->控制器管理->功能2->参数段一切正常。我的回答应该对你有帮助。(我希望如此)