嘿,我正面臨着一個相當嚴重的安全錯誤。讓我先概述一下我的代碼。編輯評論 - javascript,php一起工作
<li class="comment">
<form action="" method="POST" name="edit-form" class="edit-area">
<textarea style="width: 100%; height: 150px;"><?php echo $response->comment; ?></textarea>
</form>
<div class="comment-area" style="padding-top: 2px"><?php echo (parseResponse($response->comment)); ?></div>
<p class="ranking">
<?php if ($response->user_id == $user_id) : ?>
<a href="" class="editting" data-user="<?php echo md5(convert($response->user_id)); ?>" data-edit="<?php echo $response->short; ?>">Edit</a> • <a href="#d">Delete</a>
<?php else : ?>
<a href="#">Like (<?php echo $response->likes; ?>)</a> • <a href="#">Dislike (<?php echo $response->dislikes; ?>)</a>
<?php endif; ?>
</p>
</li>
是我在我的身上了,和這裏的相關JS
$('.editting').bind('click', function(event) {
var num = $(this).data('edit');
var user = $(this).data('user');
if ($(this).hasClass('done')) {
var newComment = $('#comment-' + num + ' .edit-area textarea').val();
var dataString = 'newComment='+ newComment + '&num=' + num;
if(newComment == '')
{
alert('Comment Cannot Be Empty!');
}
else
{
$.ajax({
type: "POST",
url: "edit.php",
data: dataString,
success: function(){}
});
$('#comment-' + num + ' .edit-area').slideDown('slow', function() {
$('#comment-' + num + ' .edit-area').addClass('invisible');
});
$('#comment-' + num + ' .comment-area').slideUp('slow', function() {
$('#comment-' + num + ' .comment-area').removeClass('invisible');
});
$(this).removeClass('done');
$(this).html('Edit');
}
}
else {
$('#comment-' + num + ' .comment-area').slideDown('slow', function() {
$('#comment-' + num + ' .comment-area').addClass('invisible');
});
$('#comment-' + num + ' .edit-area').slideUp('slow', function() {
$('#comment-' + num + ' .edit-area').removeClass('invisible');
});
$(this).html('Done');
$(this).addClass('done');
}
return false;
});
,工作正常,但我有一個問題。如果用戶發現評論(而不是他們)並使用像螢火蟲一樣的插件,他們可以用另一個替換response-> short,並編輯任何評論。當然,在edit.php中,我可以檢查響應表中的短小內容,看看用戶是否簽出,但是我想找到一種不顯示文本區域的方式,除非該用戶確定該響應。
這可能嗎?
由於提前, 請問
好,我打算做的事情edit.php反正所以我確定它是有效的,但是無論如何我還可以強化js/ – willium 2010-12-19 10:03:21
@tap - 沒有太多的事情你還沒有做,JavaScript是**開放的,這只是它是怎麼回事......我可以打開一個編輯窗口,對這個頁面的任何評論以及... *服務器*不會允許它,這是重要的。回到這裏,看看你正在嘗試做什麼......你試圖讓這個界面更好一些,以幫助某人嘗試*操縱你的網站,我不會做任何額外的事情爲此,只需在服務器端確保它的安全性,爲其他99.9%的用戶設計接口(並且仍然安全,重要!) – 2010-12-19 10:07:03
好的!謝謝尼克! – willium 2010-12-19 10:10:42