2013-02-12 58 views
0

控制器:在codeigniter中創建高安全的加密id到網站url?

function verifyuser() 
{ 
    $uri = $this->uri->uri_to_assoc(4); 
    //print_r($uri); 
    if(isset($uri['id']) && $uri['id'] != '') 

      { 
      $where = array(); 
       $where['roll_number'] = $uri['id']; 
$this->data['verification'] = $this->admin_model->verify($where); 


     } 
     else 
     { 
     $this->data['verification'] = array(); 

     } 
    $this->data['content'] = 'admin/verification'; 
    $this->view($this->data); 
} 

MODEL:

function verify($where='') 

{ 
    $this->db->select('*'); 
$this->db->from($this->db->dbprefix('members')); 
if(!(empty($where))) 
$this->db->where($where); 


$result = $this->db->get(); 
//echo $this->db->last_query(); 
    return $result->result(); 

} 

www.example.com/user/admin/verify/

www.example.com/user/admin/驗證/ hgf_877 %%% _ oi

這樣。

+0

更安全的方法是使用用戶名/密碼組合和驗證用戶。如果你仍然想按照你的方式來實現它,那麼只需要生成一個隨機單詞,使用bcrypt或sha1對它進行加密並在網址中使用它。 – ahmad 2013-02-12 15:12:25

回答

0

爲了您的安全目的,您可以使用PHP.net手冊中定義的任何編碼。但我更喜歡base64_encode和base64_decode。我正在使用我的應用程序編碼comples字符串。

<?php 
$temp = 345; 
$res = base64_encode($temp); 
echo $res;echo "<br>"; 
$result = base64_decode($res); 
echo $result; 
?> 

你也可以在這個link也找到一個小例子。