gpt4 book ai didi

php - 当 CodeIgniter 中有额外的 URL 段时,如何显示 404?

转载 作者:行者123 更新时间:2023-12-02 22:43:35 27 4
gpt4 key购买 nike

基本上,我有一个通过此 url 注册用户的 CodeIgniter 站点:
http://website.com/user/register/1

不幸的是,当您像这样在 URL 中传递额外参数时: http://website.com/user/register/1/extraargs/extraargs

这是我的代码:

<?php
class User extends CI_Controller
{
public function register($step = NULL)
{
if (($step!=NULL)&&($step == 1 || $step == 2 || $step == 3)) {
if ($step == 1){
$this->load->view('registration_step1');
}
} else {
show_404();
}
}
}
?>

它不显示 404。它只是忽略了额外的参数。我想要它,以便额外的参数不会影响 URL。如果有额外的 URL 参数,我想显示 404。你怎么做到这一点?另外,额外的 URL 段是否会影响安全性?谢谢。

最佳答案

不确定您为什么真的要这样做,但是您可以使用 func_num_args() 并据此进行验证,即,

public function register($step = NULL)
{
if ( func_num_args() > 1 ) show_404();
}

关于php - 当 CodeIgniter 中有额外的 URL 段时,如何显示 404?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10396326/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com