dongnai3960 2012-05-21 10:38
浏览 69

将javascript变量传递给php变量的安全问题[重复]

Possible Duplicate:
Preventing fraudulent submission to a scoreboard
Prevent Cheating on Javascript Game

i've found a way to pass my javascript variables to a php variable by using this:

window.location.href = ".../gameover.php?points=" + points+"&speed="+window.speed;

in the gameover.php site i use

$_GET[speed]   // and 
$_GET[points]

to access my variables. these values then get stored into a database as hiscores. but here comes my problem: if the user just types for example

.../gameover.php?points=500000&speed=85

in the address bar it also stores these variables.

i have found something that helps avoiding this but you can still get around it. on my main page i make a cookie 'notcheated' and if the user visits the page and notcheated isset then it destroys the cookie and stores the values in my hiscores but if the user visits the main page and then enters the above address for example then the cookie isset but he hasn't played the game and then the values are also stored.

does someone have any suggestions to secure my site so that people can't just enter their own hiscores.

edit: i have tried to do it with a javascript post but that didn't work. maybe i did something wrong could someone please show me an example on how i should do that?

  • 写回答

3条回答 默认 最新

  • doudao8283 2012-05-21 10:48
    关注

    The only way to prevent this is to have the game logic executed on the server side, within your PHP code. If you send any points value from the client to the server, the user can cheat.

    Example:

    /sell.php?money=10
    

    The above can be hacked, by changing 10 to 1000000. Instead, consider this:

    /sell.php?itemid=1234
    

    The server then handes the removal of the item from the player's inventory, and adds the appropriate amount of money to their account.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题