因此,我讀了一段有趣的article ,我想從CI社區獲得一些關於如何處理私人數據的反饋,例如電子郵件地址,將任何用戶數據視爲私有的權限。內容類型json,處理私人數據安全嗎?
公共數據是好的,因爲我可以控制最終的輸出,所以它的安全問題少了。
下面是我把所有的公共數據,說我的用戶的樣子,我真的想知道如何安全使用私有數據相同的方法 下一個管理控制器什麼(輸出JSON);
前端Ajax請求(users.js)我喜歡爲每個模塊創建一個新的js文件用於開發目的,然後編譯。
(function($){
var userObj = {
init: function(){
if(document.getElementById(id)){
this.populateUserData();
}
},
populateUserData : function(){
//for demonstration purposes let build output into a table
$.ajax({
url : BASE_PATH + 'users/get_active_users',
dataType : 'json',
success : function(callback){
if(callback.status === 'ok')
{
var output = "";
$.each(callback.users, function(){
var $this = this;
output += '<tr>'
output += '<td>'+$this.firstname+'</td>';
output += '<td>'+$this.lastname+'</td>';
output += '<td>'+$this.alias+'</td>';
output += '<td>'+$this.joined.date+'</td>';
output += '</tr>'
});
output += "</tr>";
$("table#id tbody").append(output);
}
}
});
}
}
$(function(){
userObj.init();
});
})(jQuery);
的HTML(允許建立一些虛擬數據)
<table class="bordered" id="id">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Alias</th>
<th>Joined</th>
</tr>
</thead>
<tbody>
//rendered out via js
</tbody>
</table>
控制器請求
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Users extends MY_Controller {
public function __construct() {parent::__construct();}
public function get_active_users()
{
if($this->input->is_ajax_request())
{
//grab all the active users(php-activerecord)
$users = User::get_all_active_users();
//render the ouput content type as json
$this->output
->set_content_type('application/json')
->set_output(json_encode($users));
}
else
{
show_404();
}
}
ActiveRecord的模型
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class User extends ActiveRecord\Model {
public static function get_all_active_users()
{
$users = self::find('all', array('conditions' => array('active=?', (int) 1)));
if($users)
{
foreach($users as $user){
$date = explode('-', date('F jS, Y - G:i', strtotime($user->created_at)));
$ret[] = array(
'joined' => array(
'date' => $date[0],
'time' => $date[1]
),
'firstname' => $user->firstname,
'lastname' => $user->lastname,
'alias' => $user->alias
);
}
return array(
'status' => 'ok',
'users' => $ret
);
}
else
{
//do something else
}
}
}
這很適合密碼,電子郵件等,但是如果我想顯示私人管理範圍內的公共屬性,如組,權限,我將如何處理這些數據?即:權限([「r」,「u」,「d」,「a」,「s」]) – Philip 2012-02-10 22:22:51
@Philip我不太確定你在問什麼。只要通過發送「虛假」請求(「清理輸入」規則在這裏適用),那些權限不能被僞造,就沒有任何內容對於通過線路發送一組權限的內在敏感性,它應該沒問題。 – 2012-02-10 22:55:49