通过AJAX处理身份验证? [英] Handling authentication through AJAX?

查看:354
本文介绍了通过AJAX处理身份验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个新手的问​​题,以AJAX专家:如果未认证用户试图发表评论的一篇文章并将其发送到通过AJAX的服务器,我需要的远程PHP脚本返回...

This is a newbie question to AJAX experts: In case an unauthenticated user tries to post a comment to an article and send it to the server through AJAX, I need the remote PHP script to return...

  • 401和登录/密码的形式,用户将填补再试,或
  • 301将用户重定向到一个整版的登录/密码的形式,如果全成,然后将用户返回到原来的评论页面。

如果可能的话,我宁愿使用AJAX为验证+邮寄,这样用户不需要看到完整的页面只是进行身份验证。可能吗? FWIW,我使用jQuery了解AJAX。

If possible, I'd rather use AJAX for both authentication + posting, so that the user doesn't need to see a full page just for authentication. Is it possible? FWIW, I'm using jQuery to learn about AJAX.

感谢你。

推荐答案

是的。你的AJAX脚本可以发出请求,比方说, comment.php 。该脚本应该检查是否会话已被授权,在 $通常是一个变量_ SESSION ['...'] 。如果是这样,则该注释应被处理。如果不是这样,用户应通过该脚本被引导登录。

Yes. Your AJAX script might be making a request to, say, comment.php. That script should check if the session has been authorised, usually a variable in $_SESSION['...']. If so, then the comment should be handled. If not, the user should be directed by that script to log in.

这篇关于通过AJAX处理身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆