2012-05-01 53 views
2

基本上,我有通過這個網址註冊用戶的CodeIgniter網站:
http://website.com/user/register/1如何在CodeIgniter中存在額外的URL段時顯示404?

不幸的是,當你在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。你怎麼做到這一點?另外,額外的網址段是否會影響安全性?謝謝。

+0

它不會影響安全性,因爲會有通過了哪些系統多餘的值根本不會使用。 –

+0

噢,好的。謝謝你的提示。 –

回答

5

不知道爲什麼你會想這樣做真的,但你可以使用func_num_args(),並從該驗證,即

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