mysql real escape string and Cookies

我怕爱的太早我们不能终老 提交于 2019-12-24 20:20:05

问题


Is there any reason this is bad form? The only user input data on the page is

// Set username and password from cookies
    $username = mysql_real_escape_string($_COOKIE["username"]);
    $password = mysql_real_escape_string($_COOKIE['password']);

I am REALLY new to the idea of sanitizing. Is there any reason this is a terrible way of doing things?


回答1:


NEVER, EVER store users' data in cookies!

Here's what I suggest:

  • store user's ID in cookie
  • generate special token and hash+salt and store them in cookies
  • store everything in database
  • get data from cookies on every page load and try searching for them in database
  • if not found, then logout a user
  • change token on every page load


来源:https://stackoverflow.com/questions/11301153/mysql-real-escape-string-and-cookies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!