Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8139177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:44:19+00:00 2026-06-06T11:44:19+00:00

This is quite a simple question – although one that is on my mind

  • 0

This is quite a simple question – although one that is on my mind right now as I start my first real-world and quite grand (in terms of size) project.

How would I go about verifying a user’s identity (username and password) when the send an Ajax request via PHP? It seems like there is a simple solution: to send both the username and password as POST variables along with the others in the request but it seems to me that solution is quite inefficient (as it has to check in the database every single time a request is made and be quite redundant for different Ajax requests).

I looked into how Twitter does their Ajax requests (such as for posting a new tweet) and I don’t see them sending any authentication information in the request – but how do they know that it is in fact me, the owner of my profile, sending the Ajax request to post the new tweet?

If it helps anyone come up with a great solution – I am using the JQuery AJAX library and the CodeIgniter PHP framework.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T11:44:20+00:00Added an answer on June 6, 2026 at 11:44 am

    Ajax requests are exactly the same as any other HTTP request. Whether it’s done via JavaScript or by typing a URI into your browser’s address bar, they are all HTTP requests.

    You are right that sending the username and password over HTTP is the wrong solution. However, sending the username/password is usually necessary once but this should only be done on HTTPS, so that it isn’t sent as plain text. Once authenticated, you can store the user ID in a server-side session variable for access in future requests.

    A little pseudo-code to help you along the way:

    if(!empty($_SESSION["userId"])) {
        // User is authenticated. Do something.
    }
    else if(!empty($_POST["username"])) {
        // User is attempting to log in. Check against database.
        $userId = getUserIdByUsernamePassword($_POST["username"], $_POST["password"]);
    
        // Store user id in session variable.
        if($userId > 0) {
            $_SESSION["userId"] = $userId;
        }
    }
    else {
        // User is not authenticated.
    }
    

    A common pitfall is to store authentication in a cookie. Cookies are stored on the client side, so if you do it this way anyone could forge authentication by creating their own cookies.

    Using session variables in PHP, a cookie is used, however it doesn’t identify the user at all, rather identifies the connection between the client and the server.

    But to successfully authenticate real-world projects, session cookies should not be relied upon. Rather, a combination of a session variable, a UUID cookie and a salted hash cookie can increase integrity of authentication… but this is another topic altogether.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably a really simple question but one I've never quite worked out
This is quite a simple question. Imagine that on the index of my webpage,
This might be a simple question for some people since it was quite hard
this is quite a simple question hopefully. Our client currently has a Flash banner
This will probably seem like a really simple question, and I am quite confused
Quite simple question, and I really wanna know the reason (the real reason) behind
This is quite a simple question. I can create a brand new FLA in
So this is quite the simple question I did not manage to find an
I hope this is quite a simple question.. I've got a compiled .exe program
This is quite a long introduction to a simple question, but otherwise there will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.