views:

33

answers:

1

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...

  • a 401 and a logon/password form which the user will fill and try again, or
  • a 301 to redirect the user to a full-page logon/password form which, if successfull, will then return the user to the original comment page.

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.

Thank you.

A: 

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.

Delan Azabani
Thanks Delan for the tip.