防止作弊

发布于 2024-12-26 03:35:47 字数 590 浏览 3 评论 0原文

我目前正在制作 Facemash 模拟,我发现它很容易作弊 ^^ 如果您在浏览器中多次输入以下内容: http://domain.com/rate.php?winner=1&loser=2,您可以让照片 1 成为获胜者。我知道可以通过 cookie 和 ip 阻止来阻止它,但我不知道具体如何操作。请帮我。谢谢!

这是一个例子(不是我的): http://facemash.moefelt.dk/

UPD 如果需要,我可以提供源代码。

UPD 1rate.php http://jsfiddle.net/6xLR6/ index.php http://jsfiddle.net/AvF4M/1/

I'm currently making a facemash analog and I found out that it's very easy to cheat ^^ If you type this in your browser several times: http://domain.com/rate.php?winner=1&loser=2, you can make photo №1 a winner. I know that it's possible to prevent it with cookies and ip-blocking, but I don't know how exactly. Please help me. Thanks!

Thant's an example (not mine):
http://facemash.moefelt.dk/

UPD I can provide a source code if needed.

UPD 1 rate.php http://jsfiddle.net/6xLR6/
index.php http://jsfiddle.net/AvF4M/1/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

抚笙 2025-01-02 03:35:47

你可以简单地使用 $_POST 代替 $_GET,作弊会更难!

cookies可以保存在缓存中,但如果用户每次都清理它,它可能就没用了。

编辑:

<form METHOD=POST ACTION="rate.php">

<table>
<tr>
        <td><img src="images/<?=$images[0]->filename?>" /></td>
        <td><img src="images/<?=$images[1]->filename?>" /></td>

<input type="radio" name="winer" value="First"> First<br>
<input type="radio" name="winer" value="Second"> Second

<input type="hidden"  name="first"  value="<?=$images[0]->image_id?>">
<input type="hidden"  name="second"  value="<?=$images[1]->image_id?>">
</tr>
</table>
</form>

在rate.php中:

<?php 
$winerId = $_POST['winer'];

if ($_POST['winer'] == $_POST['first']){
$looser = $_POST['second'];}
else { $looser = $_POST['second']; }
...

我认为你现在已经得到了你想要的一切;-)

you can simply use $_POST instread of $_GET, the cheat would be harder !

cookies can be saved in cache but if the user clean it everytime, it could be useless.

EDIT :

<form METHOD=POST ACTION="rate.php">

<table>
<tr>
        <td><img src="images/<?=$images[0]->filename?>" /></td>
        <td><img src="images/<?=$images[1]->filename?>" /></td>

<input type="radio" name="winer" value="First"> First<br>
<input type="radio" name="winer" value="Second"> Second

<input type="hidden"  name="first"  value="<?=$images[0]->image_id?>">
<input type="hidden"  name="second"  value="<?=$images[1]->image_id?>">
</tr>
</table>
</form>

In rate.php :

<?php 
$winerId = $_POST['winer'];

if ($_POST['winer'] == $_POST['first']){
$looser = $_POST['second'];}
else { $looser = $_POST['second']; }
...

I think that you got all that you want right now ;-)

夕色琉璃 2025-01-02 03:35:47

不要使用查询参数。用户 POST 请求将数据发送到服务器。

Don't use query parameters. User POST request to send data to server.

空袭的梦i 2025-01-02 03:35:47

你可以试试这个:

<?php
    session_start();

    if(isset($_POST['face']))
    {
        //add another session verifier, at least you can prevent multiple votes in 1 browser session
        if(!isset($_SESSION['done']))
        {
            $face = trim($_POST['pace']);
            //store $face votes to db
            $_SESSION['done'] = true;
        }
    }
?>


<form method="post">
    <input type="hidden" name="face" value="1" />
    <input type="image" src="image1.gif" />
</form>

<form method="post">
    <input type="hidden" name="face" value="2" />
    <input type="image" src="image2.gif" />
</form>

You can try this one:

<?php
    session_start();

    if(isset($_POST['face']))
    {
        //add another session verifier, at least you can prevent multiple votes in 1 browser session
        if(!isset($_SESSION['done']))
        {
            $face = trim($_POST['pace']);
            //store $face votes to db
            $_SESSION['done'] = true;
        }
    }
?>


<form method="post">
    <input type="hidden" name="face" value="1" />
    <input type="image" src="image1.gif" />
</form>

<form method="post">
    <input type="hidden" name="face" value="2" />
    <input type="image" src="image2.gif" />
</form>
贪了杯 2025-01-02 03:35:47

第一个问题是您要防止的攻击是什么?如果只是为了确保有人在提交答案之前加载页面,您需要:

  • 在页面中生成一个唯一的令牌,该令牌是提交表单的一部分(隐藏)
  • 提交时,检查令牌是否有效并且没有“以前没有使用过

但是,这并不能阻止有人编写一个机器人来多次投票。

如果您想确保真正的人点击了每个负载,您需要执行上述操作,并添加一个验证码来验证点击的人是否是人类。

First question is what is the attack you want to prevent? If it's simply to make sure someone loads the page before submitting an answer, you'll need to:

  • Generate a unique token in the page which is part of the submission form (hidden)
  • On submission, check that the token is valid and hasn't been previously used

However, this doesn't stop someone writing a bot to vote lots of times.

If you want to make sure that a genuine human has clicked on each load, you'll need to do the above and also include a captcha to verify that the person clicking is human.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文