通过AJAX处理身份验证?身份验证、AJAX

2023-09-10 21:41:31 作者:何以情深∝

这是一个新手的问​​题,以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.