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 7813921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:02:00+00:00 2026-06-02T05:02:00+00:00

How to verify if user have posted with XMLHttpRequest some data to PHP? This

  • 0

How to verify if user have posted with XMLHttpRequest some data to PHP?

This is the best way? If not, how I can do this?

I have the follow code

if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest') {
    // PROBABLY AJAX REQUEST
}

My question is, how I can verify php://input exists and are not empty? I think the follow code do the work, but need to know if this is a correct way:

if(file_get_contents("php://input") == '') {
    // HAVE NOT POSTED
} else {
    // POSTED
}
  • 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-02T05:02:01+00:00Added an answer on June 2, 2026 at 5:02 am

    Set a custom header as part of your AJAX function, and check for the presence of that header in your server-side code.

    Perhaps the best way to do this is to generate a key on the server-side, pass that to the client-side code that contains the AJAX call, then make AJAX send it back to the server and verify that it is a valid key. This is the most effective way to prevent someone faking an AJAX request.


    To check that php://input exists and is not empty, use this:

    $phpinput = file_get_contents("php://input");
    // From the docs: "Note: A stream opened with php://input can only be read once"
    if( !$phpinput) {
        // phpinput is empty
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that queries Active Directory to verify user existence. I am
I have the same issue as this user: ant - not recognized as an
I have an MVC application that needs to login and verify a user against
I have this code: btn_jouer.onRelease = function () { verif = txt_email_user.text; if (txt_email_user.text
I made this function to verify a user's twitter credentials. Its running on two
I am trying to verify whether an object is null or not, using this
I want to verify whether an e-mail is real or not. Some body told
I have some actions that requires a specific user permission to be accessed, so
Edit: After addressing some issues that may or may not have been causing problems,
I have the following code: try { //Create connection SQLiteConnection conn = DBConnection.OpenDB(); //Verify

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.