我有一個數據表與服務器端處理,但我不知道如何保護ajax調用,因爲如果有人去ajax PHP文件可以讀取所有的內容。安全的Ajax調用
這是我的jquery:
$(document).ready(function() {
$('#netflow').DataTable({
aaSorting: [[ 5, "desc" ]],
responsive: {
details: {
renderer: function (api, rowIdx) {
var data = api.cells(rowIdx, ':hidden').eq(0).map(function (cell) {
var header = $(api.column(cell.column).header());
return '<p style="color:#00A">'+header.text()+' : '+api.cell(cell).data()+'</p>'; // changing details mark up.
}).toArray().join('');
return data ? $('<table/>').append(data) : false;
}
}
},
processing: true,
serverSide: true,
ajax: "/adm/includes/netflow_processing.php",
});
var oTable = $('#netflow').dataTable();
var table = $('#netflow').DataTable();
$('#netflow_filter input').unbind();
$('#netflow_filter input').bind('keyup', function(e) {
if(e.keyCode == 13) {
oTable.fnFilter(this.value);
}
});
// Añadir filtro para cad acelda
$('#netflow tfoot th').each(function (i) {
$(this).html('<input type="text"/style = "width: 100%; " placeholder="Filtra...">');
});
// Aplicar filtro al introducir en cada celda
table.columns().eq(0).each(function (colIdx) {
$('input', table.column(colIdx).footer()).on('keyup change', function() {
table
.column(colIdx)
.search(this.value)
.draw();
});
});
});
這是AJAX腳本:
<?php
$table = 'netflow';
$primaryKey = 'id';
$columns = array(
array('db' => 'flow_src', 'dt' => 0),
array('db' => 'flow_dst', 'dt' => 1),
array('db' => 'flow_proto', 'dt' => 2),
array('db' => 'out_packets', 'dt' => 3),
array('db' => 'in_packets', 'dt' => 4),
array('db' => 'flow_start', 'dt' => 5)
);
$sql_details = array(
'user' => '6g43tfr3',
'pass' => 'XXXXXXXXX',
'db' => 'DBNAME',
'host' => 'bbdd.localdomain'
);
require('ssp.class.php');
echo json_encode(
SSP::simple($_GET, $sql_details, $table, $primaryKey, $columns)
);
我怎樣才能讓一個哈希/令牌請求?
正是我想要的,簡單而實用。非常感謝你!。 –
@RaduRadu,'HTTP_REFERER'可以很容易地被修改,例如當數據挖掘時攻擊者會首先改變。 –
@ Gyrocode.com - 這樣的聲明確實需要一些概念驗證:) HTTP_REFERER不能在瀏覽器中更改,例如通過發送帶有AJAX的僞造標頭。你可以使用CURL或類似的方式來「欺騙」HTTP_REFERER,也就是通過創建一個專門用於在套接字上運行的特定腳本的腳本,但是「攻擊者」仍然需要知道他需要包含HTTP_REFERER,將被接受。 – davidkonrad