Mic*_*ina 2 php url arguments codeigniter segments
基本上,我有一个CodeIgniter站点,通过此URL注册用户: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();
}
}
}
?>
Run Code Online (Sandbox Code Playgroud)
它没有显示404.它只是忽略了额外的参数.我想要它,以便额外的参数不会影响URL.如果有额外的URL参数,我想显示404.你怎么做到这一点?此外,额外的URL细分可以影响安全性吗?谢谢.
不确定为什么你真的想这样做,但你可以使用func_num_args()并验证,即,
public function register($step = NULL)
{
if ( func_num_args() > 1 ) show_404();
}
Run Code Online (Sandbox Code Playgroud)