将用户名和密码信息安全地传递给 Ajax php 脚本
我有一个 PHP 脚本,用于通过 AJAX 将数据返回到网页。在 PHP 脚本中,登录网站的特定用户会建立与 MySQL 的连接,下载数据然后返回到网页。为此,用户名和密码信息通过 $_GET 变量传递给脚本(我知道,非常糟糕)。这是匆忙完成的,但现在我想解决这个问题。明显的问题是,这些凭据会在加载网页时显示。
将这些变量传递给 PHP 脚本的最佳(最安全)方法是什么?加密?
我这一切都错了吗?有更好的方法吗?
I have a PHP script that is used to return data to a web page via AJAX. In the PHP script a connection to MySQL is made by the specific user logged into the website, the data is downloaded then returned to the web page. For this purpose username and password info are passed to the script via $_GET variables (I know, very bad). This was done in haste but now I want to fix this problem. The obvious problem is that these credentials show up when the webpage page it loads.
What is the best (most secure) way of passing these variables to the PHP script? Encryption?
Am I going about this all wrong? Is there a better way of doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
加密在这里有点无用,因为 JavaScript 是客户端而不是服务器端。使其更安全的一种方法是使用 SSL,并且不通过 AJAX 处理登录,而是在不使用 AJAX 的情况下处理 POST。
Encryption would be kind of useless here as JavaScript is client-side and not server side. A way to have it more secure is using SSL and don't handle the login via AJAX but POST without using AJAX.
好吧,如果您不想将其重新加工为 POST(请参阅 Kaisers 答案 +1),您可以传递一些额外的唯一加密 $_GET 变量,这些变量在实际处理或返回任何数据之前就像身份验证一样。
Well, if you don't feel like reworking it into POST (see Kaisers answer +1), you could pass some additional unique encrypted $_GET variables that would act like authentication before any data is actually processed or returned.