php - 编辑评论 - javascript、php 协同工作

标签 php javascript jquery validation comments

大家好,我面临一个相当严重的安全错误。让我首先概述我的代码。

<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> &bull; <a href="#d">Delete</a> 
            <?php else : ?>
                <a href="#">Like (<?php echo $response->likes; ?>)</a> &bull; <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;


        });

工作正常,但我遇到了问题。如果用户找到评论(不是他们自己的)并使用像 firebug 这样的插件,他们可以用另一个替换响应->短,并编辑任何评论。当然,在 edit.php 中,我可以根据响应表检查短路并查看用户是否 checkout ,但我想找到一种不显示文本区域的方法,除非该用户确定该响应.

这可能吗?

提前致谢, 会

最佳答案

Is this possible?

当然...但它不会阻止用户/修复您的安全漏洞。要解决此问题,请检查服务器端始终仔细检查服务器端应安全的任何内容,永远不要相信您的输入。用户尝试恶意行为不会被 JavaScript 中的任何内容阻止...将他们不应该做的数据发送到您的服务器正是他们会做的事情首先。

关于php - 编辑评论 - javascript、php 协同工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4482316/

相关文章:

php - 在一个查询mysql中添加和替换

php - SQL SELECT 查询没有结果也没有错误

php - 多列 Symfony Doctrine 上的多词搜索

jquery - 在 jQuery 的 .text() 返回的长输出中插入逗号或空格

php - 使用布局模板的 flash 消息重定向回来

php - 将 JavaScript 迁移到 PHP

javascript - 如何做 '@somename' 像 Twitter 功能?

javascript - 查找上一个按钮的 ID

javascript - CodeMirror - 在有多个编辑器时将文本插入编辑器

javascript - 有条件地加载外部脚本不起作用,没有错误